Bird
0
0

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

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

SELECT customer_id, product_id, SUM(quantity) FROM orders GROUP BY customer_id, product_id;
ATotal quantity ordered for all orders
BTotal quantity ordered per customer only
CTotal quantity ordered per product only
DTotal quantity ordered per customer and product combination
Step-by-Step Solution
Solution:
  1. Step 1: Understand GROUP BY columns

    The query groups rows by both customer_id and product_id, so each group is a unique pair.
  2. Step 2: Analyze aggregation

    SUM(quantity) calculates total quantity for each customer-product pair.
  3. Final Answer:

    Total quantity ordered per customer and product combination -> Option D
  4. Quick Check:

    GROUP BY multiple columns aggregates per unique column pairs [OK]
Quick Trick: SUM with GROUP BY multiple columns sums per unique pairs [OK]
Common Mistakes:
MISTAKES
  • Assuming aggregation is per single column
  • Ignoring grouping columns in result
  • Confusing SUM with COUNT

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes