Bird
0
0

Given the table orders with columns customer_id and order_total, what will this query return?

medium📝 query result Q13 of 15
SQL - GROUP BY and HAVING
Given the table orders with columns customer_id and order_total, what will this query return?
SELECT customer_id, COUNT(*) AS order_count FROM orders GROUP BY customer_id ORDER BY order_count ASC;
ASyntax error due to incorrect ORDER BY usage.
BList of customers with their order counts sorted from highest to lowest.
CList of customers with total order amounts sorted ascending.
DList of customers with their order counts sorted from lowest to highest.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the GROUP BY and COUNT

    The query groups rows by customer_id and counts orders per customer.
  2. Step 2: Analyze ORDER BY order_count ASC

    Ordering by order_count ascending sorts customers from fewest to most orders.
  3. Final Answer:

    List of customers with their order counts sorted from lowest to highest. -> Option D
  4. Quick Check:

    ORDER BY ASC sorts ascending [OK]
Quick Trick: ORDER BY ASC sorts from smallest to largest [OK]
Common Mistakes:
MISTAKES
  • Assuming ORDER BY ASC sorts descending
  • Confusing COUNT with SUM
  • Thinking query returns total order amounts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes