Previous Page
Next Page

9.9. Exercises

Unless specified otherwise, use the Student_course database to answer the following questions. Also, use appropriate column headings when displaying your output.

  1. Display a list of courses (course names) that have prerequisites and the number of prerequisites for each course. Order the list by the number of prerequisites.

  2. How many juniors (class = 3) are there in the Student table?

  3. Group and count all MATH majors by class and display the count if there are two or more in a class. (Remember that class here refers to freshman, sophomore, and so on and is recorded as 1, 2, and so on.)

  4. Print the counts of As, Bs, and so on from the Grade_report table.

    1. Using temporary tables (local or global), print the minimum counts of the grades (that is, if there were 20 As, 25 Bs, and 18 Cs, you should print the minimum count of grades as C) from the Grade_report table.

    2. Using inline views, print the maximum counts of the grades (that is, if there were 20 As, 25 Bs, and 18 Cs, you should print the maximum count of grades as B) from the Grade_report table.

    3. Why would you not want to use views for this problem?

  5. Print the counts of course numbers offered in descending order by count. Use the Section table only.

  6. Create a table with names and number-of-children (NOC). Populate the table with five or six rows. Use COUNT, SUM, AVG, MIN, and MAX on the NOC attribute in one query and confirm that the numbers you get are what you expect.

  7. Create a table of names, salaries and job locations. Populate the table with at least 10 rows and no fewer than three job locations. (There will be several employees at each location.) Find the average salary for each job location with one SELECT.

  8. Print an ordered list of instructors and the number of As they assigned to students. Order the output by number of As (lowest to greatest). You can (and probably will) ignore instructors that assign no As.

  9. Create a table called Employees with a name, a salary and job title. Include exactly six rows. Make the salary null in one row, the job title null in another, and both the salary and the job title in another. Use this data:

    Name

    Salary

    Title

    Mary

    1000

    Programmer

    Brenda

    3000

     

    Stephanie

     

    Artist

    Alice

     

     

    Lindsay

    2000

    Artist

    Christina

    500

    Programmer


    1. Display the table.

    2. Display count, sum, maximum, minimum, and average salary.

    3. Display count, sum, maximum, minimum, and average salary, counting salary as 0 if no salary is listed.

    4. Display the average salary grouped by job title on the table as is.

    5. Display the average salary grouped by job title when null salary is counted as 0.

    6. Display the average salary grouped by job title when salary is counted as 0 if it is null and include a value for "no job title."

  10. Find the instructor and the section where the maximum number of As were awarded.

  11. Find the COUNT of the number of students by class who are taking classes offered by the computer science (COSC) department. Perform the query in two ways: once using a condition in the WHERE clause and once filtering with a HAVING clause. (Hint: These queries need a five-table join.)

Delete (DROP) all of your "scratch" tables (the ones you created just for this exercise: Employees, NOC, and any others you may have created).


Previous Page
Next Page