SELECT dno, COUNT(ssn)
FROM employee
GROUP BY dno
dno COUNT(ssn)
----------- ---------------------
1 1
4 3
5 4
|
|
Answer:
Fact:
The result of a sub-query is a relation
In other words:
(SELECT dno, COUNT(ssn)
FROM employee
GROUP BY dno)
is a relation
|
|
Solution:
From the above discussion, we can find the
most number of employees in any dept as follows:
select max(NEmps)
from (select count(ssn) NEmps
from employee
group by dno) A
max(NEmps)
---------------
4
|
|
Solution - part 1: we first find the most number of dependents of any employee
1. Here are the dependents of each employee:
SELECT *
FROM dependent
essn name sex bdate relationship
--------- ---------- ------ ---------- ------------
123456789 Micheal M 01-JAN-78 SON
123456789 Alice F 31-DEC-78 DAUGHTER
123456789 Elizabeth F 05-MAY-57 SPOUSE
333445555 Alice F 05-APR-76 DAUGHTER
333445555 Theodore M 25-OCT-73 SON
333445555 Joy F 03-MAY-48 SPOUSE
987654321 Abner M 29-FEB-32 SPOUSE
|
Solution - part 2: find employees who has the most number of dependents
1. Here are the employees and their dependents:
select fname, lname, name
from employee, dependent
where ssn=essn
fname lname name
------ -------- ----------
Frankl Wong Alice
Frankl Wong Theodore
Frankl Wong Joy
Jennif Wallace Abner
John Smith Alice
John Smith Elizabeth
John Smith Micheal
|