Bird
0
0

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

medium📝 query result Q4 of 15
SQL - GROUP BY and HAVING
Given the table orders with columns customer_id and order_amount, what will this query return?

SELECT customer_id, SUM(order_amount) FROM orders GROUP BY customer_id;
ANumber of orders per customer
BList of all orders sorted by customer_id
CTotal order amount for each customer
DAverage order amount for all customers
Step-by-Step Solution
Solution:
  1. Step 1: Understand the query components

    The query groups rows by customer_id and sums order_amount for each group.
  2. Step 2: Interpret the result

    SUM(order_amount) calculates total spending per customer, grouped by customer_id.
  3. Final Answer:

    Total order amount for each customer -> Option C
  4. Quick Check:

    GROUP BY customer_id with SUM = total per customer [OK]
Quick Trick: SUM with GROUP BY gives totals per group [OK]
Common Mistakes:
MISTAKES
  • Thinking it counts orders instead of sums
  • Assuming it sorts orders
  • Confusing average with sum

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes