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, COUNT(*), SUM(order_amount) FROM orders GROUP BY customer_id;
ASyntax error due to missing WHERE clause
BTotal orders for all customers combined
CList of customers without any aggregation
DNumber of orders and total amount per customer
Step-by-Step Solution
Solution:
  1. Step 1: Understand the query components

    The query groups rows by customer_id, counts orders per customer, and sums order amounts per customer.
  2. Step 2: Interpret the output

    Each row shows a customer_id, number of orders, and total order amount for that customer.
  3. Final Answer:

    Number of orders and total amount per customer -> Option D
  4. Quick Check:

    GROUP BY with COUNT and SUM = Aggregated per group [OK]
Quick Trick: GROUP BY aggregates per group, not entire table [OK]
Common Mistakes:
MISTAKES
  • Thinking COUNT(*) counts all rows ignoring GROUP BY
  • Expecting total for all customers in one row
  • Assuming WHERE is required for GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes