Another Possible SQL Query Uses Nesting As Follows
Another Possible SQL Query Uses Nesting As Follows
(a) Retrieve the names of employees in department 5 who work more than 10 hours per
week on the 'ProductX' project.
Result:
LNAME FNAME
Smith John
English Joyce
(b) List the names of employees who have a dependent with the same first name as
themselves.
Result (empty):
LNAME FNAME
Result:
LNAME FNAME
Smith John
Narayan Ramesh
English Joyce
(d) For each project, list the project name and the total hours per week (by all
employees) spent on that project.
Result:
PNAME SUM(HOURS)
ProductX 52.5
ProductY 37.5
ProductZ 50.0
Computerization 55.0
Reorganization 25.0
Newbenefits 55.0
Result:
AVG(SALARY)
31000
(h) List the last names of department managers who have no dependents.
Result:
LNAME FNAME
Borg James
Answers:
Result:
DNAME COUNT(*)
Research 4
Administration 3
Headquarters 1
(j) Suppose we want the number of male employees in each department rather than all
employees as in
The query may still be specified in SQL by using a nested query as follows (not all
implementations may support this type of query):
Result:
DNAME COUNT(*)
Research 3
Administration 1
Headquarters 1
Company Database(Figures 7.5 and 7.6 of the COMPANY database from
Elmasri and Navathe) :