Bird
0
0

You want to find customers who placed more than 3 orders and spent over $500 total. Which query pattern correctly achieves this?

hard📝 Application Q15 of 15
SQL - Advanced Query Patterns
You want to find customers who placed more than 3 orders and spent over $500 total. Which query pattern correctly achieves this?
SELECT customer_id, COUNT(*), SUM(amount) FROM orders GROUP BY customer_id HAVING COUNT(*) > 3 AND SUM(amount) > 500;
AUse WHERE to filter counts and sums after grouping.
BUse GROUP BY only without HAVING or WHERE.
CUse HAVING to filter groups based on aggregated values.
DUse ORDER BY to filter groups with conditions.
Step-by-Step Solution
Solution:
  1. Step 1: Understand filtering after aggregation

    WHERE filters rows before grouping; HAVING filters groups after aggregation.
  2. Step 2: Identify correct clause for aggregated conditions

    Conditions on COUNT and SUM require HAVING, not WHERE.
  3. Final Answer:

    Use HAVING to filter groups based on aggregated values. -> Option C
  4. Quick Check:

    HAVING filters aggregated group results [OK]
Quick Trick: Use HAVING for conditions on grouped data [OK]
Common Mistakes:
  • Using WHERE instead of HAVING for aggregates
  • Forgetting to group before filtering aggregates
  • Using ORDER BY to filter data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes