Bird
0
0

Given a table orders with columns customer_id and amount, what will this query return?

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

SELECT customer_id, SUM(amount) FROM orders GROUP BY customer_id;
ATotal amount spent by each customer
BTotal amount spent by all customers combined
CList of customers without totals
DError because SUM() needs no GROUP BY
Step-by-Step Solution
Solution:
  1. Step 1: Understand GROUP BY with SUM()

    The query groups rows by customer_id and sums amounts per group.
  2. Step 2: Interpret the output

    Each row shows a customer and their total spending.
  3. Final Answer:

    Total amount spent by each customer -> Option A
  4. Quick Check:

    GROUP BY customer_id + SUM = totals per customer [OK]
Quick Trick: GROUP BY groups rows; SUM calculates per group [OK]
Common Mistakes:
MISTAKES
  • Thinking SUM totals all rows without grouping
  • Expecting list without totals
  • Assuming query causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes