Bird
0
0

You have a table Orders with columns CustomerID, OrderAmount. How do you write a query to find the total order amount for each customer?

hard📝 Application Q15 of 15
SQL - Aggregate Functions
You have a table Orders with columns CustomerID, OrderAmount. How do you write a query to find the total order amount for each customer?
ASELECT SUM(OrderAmount) FROM Orders GROUP BY CustomerID;
BSELECT CustomerID, SUM(OrderAmount) FROM Orders;
CSELECT CustomerID, TOTAL(OrderAmount) FROM Orders GROUP BY CustomerID;
DSELECT CustomerID, SUM(OrderAmount) FROM Orders GROUP BY CustomerID;
Step-by-Step Solution
Solution:
  1. Step 1: Use GROUP BY to group rows by CustomerID

    This groups all orders per customer so we can sum their amounts.
  2. Step 2: Use SUM(OrderAmount) to add orders per group

    SUM() calculates total order amount for each customer group.
  3. Final Answer:

    SELECT CustomerID, SUM(OrderAmount) FROM Orders GROUP BY CustomerID; -> Option D
  4. Quick Check:

    GROUP BY + SUM() = total per group [OK]
Quick Trick: Use GROUP BY with SUM() to total per group [OK]
Common Mistakes:
MISTAKES
  • Missing GROUP BY causes error or wrong result
  • Using TOTAL() which is not standard SQL
  • Selecting SUM() without grouping CustomerID

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes