Consider the given query:
________ CustID , COUNT() _____ SALE ________ CustID ____ Count() >1
Fill the following words in the above query in correct order:
A. SELECT
B. FROM
C. GROUP BY
D. HAVING
Consider the given query:
________ CustID , COUNT() _____ SALE ________ CustID ____ Count() >1
Fill the following words in the above query in correct order:
A. SELECT
B. FROM
C. GROUP BY
D. HAVING
Solution
SQL clauses must appear in the order SELECT, FROM, GROUP BY, HAVING. The completed query is:
SELECT CustID, COUNT(*) FROM SALE GROUP BY CustID HAVING COUNT(*) > 1
It lists each customer who appears in more than one sale, along with the number of sales.
Option 2: HAVING cannot come before GROUP BY, because it filters the groups that GROUP BY creates.
Extra: WHERE filters rows before grouping, while HAVING filters groups after grouping, which is why a condition on COUNT(*) must go in HAVING.
Related questions:
2026: 29 May Shift 2
2026: 21 May Shift 1
2026: 29 May Shift 1