Which SQL query correctly filters out groups with a total sales amount greater than 10,000?
Which SQL query correctly filters out groups with a total sales amount greater than 10,000?
Solution
HAVING filters groups after GROUP BY, and it can use aggregate functions such as . So HAVING SUM(Sales) > 10000 keeps only those customers whose total sales exceed 10,000.
Option 1: WHERE runs before grouping, so it cannot use an aggregate like SUM() and the query gives an error.
Option 2: ORDER BY only sorts the result and never removes groups.
Option 4: WHERE filters individual rows (single orders above 10,000), not the group total.
Memory trick: WHERE filters rows before grouping, HAVING filters groups after grouping.
Related questions:
2025: 20 May Shift 1
2025: 3 June Shift 2
2026: 29 May Shift 1
2026: 29 May Shift 1