MIDTERM
CS122, Summer 2008


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 11:30AM, 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". Note that you may not use emp_details_view in your query.

  1. Find the name of the Accounting Department manager.
  2. Find the name of the department that John Russell works for.
  3. Find the number of departments located in Europe.
  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 names of the employees who were hired in the summer of 2006. Note that "summer" includes the months of June, July, and August.
  6. Find the names of the employees whose salaries are higher than their managers'.
  7. Find the year in which the largest number of employees were hired. The result should include the year and the number of employees hired in that year.
  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 been demoted, i.e. the average salary for their current job title is lower than the average salary for their previous job title.
  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.