What will be the sequence of the given SQL clauses to display the Customer Id (CustID) and number of cars purchased if the customer purchased more than 1 car from SALE table?
A. GROUP BY CustID
B. COUNT(*)
C. HAVING COUNT (*)>1
D. FROM SALE
E. SELECT CustID
What will be the sequence of the given SQL clauses to display the Customer Id (CustID) and number of cars purchased if the customer purchased more than 1 car from SALE table?
A. GROUP BY CustID
B. COUNT(*)
C. HAVING COUNT (*)>1
D. FROM SALE
E. SELECT CustID
Solution
SQL clauses must follow the fixed order SELECT, FROM, GROUP BY, HAVING. COUNT(*) is not a separate clause. It is part of the SELECT list, so it comes right after CustID.
E. SELECT CustID
B. COUNT(*)
D. FROM SALE
A. GROUP BY CustID
C. HAVING COUNT(*)>1
The full query is: SELECT CustID, COUNT() FROM SALE GROUP BY CustID HAVING COUNT()>1;
Options 1, 2 and 3: GROUP BY or COUNT(*) is placed before FROM, which is invalid because FROM must come before GROUP BY and HAVING.
HAVING filters groups after GROUP BY, so it always comes last here. WHERE would filter rows before grouping and cannot use COUNT(*).
Related questions:
2026: 21 May Shift 1
2026: 26 May Shift 1