Department (dNumber, dName)
Employee (SSN, eName, salary, /dNumber/)
Project (pNumber, pName, pLocation)
WorksOn (/SSN/, /pNumber/, hours)
These are the tables I am working with. I want to list all department numbers and names where more than 5 employees work, and count the number of those employees whose salaries are greater than 40,000. I want to practice using subqueries.
Here is what I wrote:
SELECT T.dNumber, T.dName, COUNT(T.SSN)
FROM
(
SELECT d.dNumber, d.dName, e.SSN
FROM Department d, Employee e
WHERE e.salary > 40000 AND d.dNumber = e.dNo
) as T
GROUP BY dNumber, dName
HAVING COUNT(T.SSN) > 5;
But it looks and feels redundant. It's almost as if I don't really need to use subqueries. Any ideas?
Thank you!