SOL-C01 · Question #86
You have a table named 'CUSTOMER ORDERS with columns customer id', order date' , and 'order amount'. You want to retrieve the top 5 customers who placed orders on a specific date ('2023-01-15') based
The correct answer is A. SELECT customer_id, AS total_amount FROM CUSTOMER_ORDERS WHERE order_date =. Option A is correct because it combines all required elements: a WHERE order_date = '2023-01-15' clause to filter by the specific date, SUM(order_amount) AS total_amount to aggregate each customer's total, GROUP BY customer_id to collapse rows per customer, ORDER BY total_amount
Question
You have a table named 'CUSTOMER ORDERS with columns customer id', order date' , and 'order amount'. You want to retrieve the top 5 customers who placed orders on a specific date ('2023-01-15') based on the total order amount. Which SQL query will achieve this?
Options
- ASELECT customer_id, AS total_amount FROM CUSTOMER_ORDERS WHERE order_date =
- BSELECT customer_id, AS total_amount FROM CUSTOMER_ORDERS GROUP BY customer_id
- CSELECT customer_id, AS total_amount FROM CUSTOMER_ORDERS WHERE order_date =
- DSELECT customer_id, order_amount FROM CUSTOMER_ORDERS WHERE order_date = '2023-
- E`sql SELECT TOP 5 customer_id, AS total_amount FROM CUSTOMER_ORDERS WHERE
How the community answered
(51 responses)- A76% (39)
- B2% (1)
- C2% (1)
- D6% (3)
- E14% (7)
Explanation
Option A is correct because it combines all required elements: a WHERE order_date = '2023-01-15' clause to filter by the specific date, SUM(order_amount) AS total_amount to aggregate each customer's total, GROUP BY customer_id to collapse rows per customer, ORDER BY total_amount DESC to rank by highest spender, and LIMIT 5 (or equivalent) to return only the top 5.
Why the distractors fail:
- B omits the
WHEREdate filter, so it aggregates across all dates, not just2023-01-15. - C appears structurally similar to A but is missing either the
ORDER BYorLIMITclause, meaning results aren't ranked or capped at 5. - D selects raw
order_amountwithoutSUM()orGROUP BY, returning individual order rows rather than aggregated customer totals. - E uses
SELECT TOP 5(SQL Server syntax) but lacksGROUP BY, so the aggregation is broken and results are undefined.
Memory tip: Think of the query as a pipeline - filter first (WHERE), group and sum (GROUP BY + SUM), rank (ORDER BY DESC), trim (LIMIT 5). Any option missing a step in this pipeline will produce wrong results.
Topics
Community Discussion
No community discussion yet for this question.