MIDTERM
CS122, Fall 2011
Please put your queries in an SQL script file midterm.sql and upload
it to CSNS.
Note that file
uploading will be disabled automatically after 3:30PM, and late submission will not
be
accepted.
[SQL] (30pt) Complete the following queries using the Human Resource Database.
For all the queries that ask for "names of the employees", the results
should have the employee names in one column in the form of
"last
name, first name", and the names should be ordered alphabetically in ascending order. Note that you may not use emp_details_view in your query.
- Find the names of the departments that are located in Europe.
- Find the name and phone number of the Sales Department manager.
- List the number of employees in each country.
Display 0 for countries that do not have any employees. The results
should be ordered by the number of employees in descending order.
- Find the area code (i.e. the first three digits of a domestic phone number) of the address 2004 Charade Rd, Seattle, Washington.
- Find the month in which the largest number of employees were
hired. The result should include the month in the form of "month, year" in one column, and the number of employees
hired in that month. Note that the result should display the full name of the month, e.g. January instead of just 1 or JAN.
- Find the names of the employees whose salaries are higher than their managers'.
- Find the number of employees managed by John Russell's manager. You may not use subquery for this query.
- List the names of the employees whose salary is above the average
for their job title. The average salary for a particular job
title is the average of min_salary and max_salary in the jobs table.
- Find the names of the employees who have held at least three
different job titles. You must use the inner join syntax for this query. The results should not have any duplicates.
- The convention for the email address of an employee is to
concatenate the first letter of the employee's first name with the
employee's last name, all in capital letters. And if an employee's last
name is longer than 7 letters, only the first 7 letters are used. For
example, Steven King's email address is SKING, and Valli Pataballa's
email address is VPATABAL. Write a query to find the names of the
employees whose email addresses do not follow this convention.