Practice free →
HomeGATE CSEcomputerscienceDatabase Management Systems › In a SELECT with GROUP BY, the correct way to ke…

In a SELECT with GROUP BY, the correct way to keep only groups whose average salary exceeds 50000 is

Ause WHERE AVG(salary) > 50000 before GROUP BY
Buse ORDER BY AVG(salary) > 50000
Cuse DISTINCT to filter the groups
Duse HAVING AVG(salary) > 50000 after GROUP BY
Answer & Solution
Correct answer: D. use HAVING AVG(salary) > 50000 after GROUP BY
HAVING is the clause that filters AFTER aggregation. WHERE filters individual rows BEFORE grouping (and aggregate functions are not allowed in WHERE for that reason). ORDER BY only sorts; DISTINCT only removes duplicate rows.
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions