Database HW3 Chap5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Database System

Homework #3 (Chapter 5)

5.6. Specify the following queries in SQL on the database schema in Figure 1.2.

a. Retrieve the names and major departments of all straight-A students (students who have a
grade of A in all their courses).
b. Retrieve the names and major departments of all students who do not have a grade of A in
any of their courses.

1
5.7. In SQL, specify the following queries on the database in Figure 3.5 using the concept of nested
queries and concepts described in this chapter.

a. Retrieve the names of all employees who work in the department that has the employee
with the highest salary among all employees.
b. Retrieve the names of all employees whose supervisor’s supervisor has ‘888665555’ for
Ssn.
c. Retrieve the names of employees who make at least $10,000 more than the employee who
is paid the least in the company.

2
5.8. Specify the following views in SQL on the COMPANY database schema shown in Figure 3.5.
a. A view that has the department name, manager name, and manager salary for every
department.
b. A view that has the employee name, supervisor name, and employee salary for each
employee who works in the ‘Research’ department.
c. A view that has the project name, controlling department name, number of employees, and
total hours worked per week on the project for each project.
d. A view that has the project name, controlling department name, number of employees, and
total hours worked per week on the project for each project with more than one employee
working on it.

3
5.9. Consider the following view, DEPT_SUMMARY, defined on the COMPANY database in
Figure 3.6:
CREATE VIEW DEPT_SUMMARY (D, C, Total_s, Average_s)
AS SELECT Dno, COUNT(*), SUM(Salary), AVG(Salary)
FROM EMPLOYEE
GROUP BY Dno;

4
State which of the following queries and updates would be allowed on the view. If a query or
update would be allowed, show what the corresponding query or update on the base relations
would look like, and give its result when applied to the database in Figure 3.6.
a. SELECT *
FROM DEPT_SUMMARY;
b. SELECT D, C
FROM DEPT_SUMMARY
WHERE TOTAL_S > 100000;
c. SELECT D, AVERAGE_S
FROM DEPT_SUMMARY
WHERE C > (SELECT C FROM DEPT_SUMMARY WHERE D=4);
d. UPDATE DEPT_SUMMARY
SET D=3
WHERE D=4;
e. DELETE FROM DEPT_SUMMARY
WHERE C > 4;

You might also like