SQL & Queries


Answer & solution
Answer: LEFT JOIN all departments to qualifying employees and count the matching employee department values, including zeros. (no official key was published)
To interpret “for each department” literally, start from DEPT so that departments with zero qualifying employees are retained:
SELECT d."Dept-no", COUNT(e."Dept-no") AS high_salary_count FROM DEPT AS d LEFT JOIN EMP AS e ON e."Dept-no" = d."Dept-no" AND e.Salary > 100000 GROUP BY d."Dept-no";
The salary condition belongs in ON: placing it in WHERE would discard the null-extended rows and remove zero-count departments. COUNT(e."Dept-no") counts only actual matches, since a matched equality implies a non-null employee department value; COUNT(*) would incorrectly count the null-extended row as one. Salaries equal to 100000 do not qualify. This assumes the conventional unique department number in DEPT.
If the expected interpretation asks only for department numbers represented by qualifying employees, the shorter traditional query is:
SELECT "Dept-no", COUNT(*) AS high_salary_count
FROM EMP
WHERE Salary > 100000
GROUP BY "Dept-no";
That version omits zero-count departments. It is a different coverage choice, so the all-department query is preferable for the literal wording. Attribute names are quoted to preserve the printed hyphens.