Similar questions 1 more →
SQL & Queries


Answer & solution
Answer: D (no official key was published)
1. WHERE sex=M filters the outer rows to male employees before grouping by department. HAVING compares each such group’s average salary with the uncorrelated subquery SELECT AVG(salary) FROM Employee, which averages all employees company-wide.
2. Therefore it returns departments whose male employees’ average exceeds the overall company average. The inner query has no male filter and is not restricted to the same department.
3. Teaching check: Read SQL in stages: WHERE keeps only males; GROUP BY makes one male group per department; HAVING compares its average against a separately computed company-wide average. There is no correlation predicate linking the subquery to the department, and no sex filter inside it.