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.

  1. Find the names of the departments that are located in Europe.
  2. Find the name and phone number of the Sales Department manager.
  3. 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.
  4. Find the area code (i.e. the first three digits of a domestic phone number) of the address 2004 Charade Rd, Seattle, Washington.
  5. 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.
  6. Find the names of the employees whose salaries are higher than their managers'.
  7. Find the number of employees managed by John Russell's manager. You may not use subquery for this query.
  8. 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.
  9. 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.
  10. 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.