MIDTERM
CS122, Summer 2007


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 all queries can be solved without using subqueries, but you may use subqueries if you want to.

  1. Find the job title of John Russell.
  2. Find in which country John Russell works.
  3. Find the names of the employees who are managed by John Russell.
  4. Find the names of the employees whose phone numbers are international numbers, i.e. the phone numbers start with 011.
  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. List the number of departments in each region, and order the results by region name. Display 0 if there is no department in the region.
  7. Find the names of the employees whose salaries are higher than their managers'.
  8. List the average employee salary by years of service. The results should include years of service and average salary, and ordered by years of service in descending order.
  9. 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.
  10. 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.