CS FundamentalsModerateGATE CS · PSU (ISRO/BARC)

A query must list departments whose average salary exceeds 50000, considering only employees hired after 2020. Which clause placement is correct?

  1. A. Hiring filter in WHERE, average test in HAVING
  2. B. Both conditions in HAVING with no WHERE
  3. C. Both conditions in WHERE
  4. D. Average test in WHERE, hiring filter in HAVING

Correct answer: A. Hiring filter in WHERE, average test in HAVING

WHERE filters rows before grouping and cannot contain aggregates; HAVING filters groups and is where AVG(salary) > 50000 belongs. Putting a per-row filter in HAVING is invalid unless it is grouped.

More DBMS and SQL questions

Exams that ask this topic