Bird
0
0

Which of the following SQL queries correctly filters groups having a total sales greater than 1000?

easy📝 Syntax Q12 of 15
SQL - GROUP BY and HAVING
Which of the following SQL queries correctly filters groups having a total sales greater than 1000?
ASELECT store, SUM(sales) FROM sales_data WHERE SUM(sales) > 1000 GROUP BY store;
BSELECT store, SUM(sales) FROM sales_data WHERE sales > 1000 GROUP BY store;
CSELECT store, SUM(sales) FROM sales_data GROUP BY store HAVING SUM(sales) > 1000;
DSELECT store, SUM(sales) FROM sales_data HAVING SUM(sales) > 1000 GROUP BY store;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct HAVING usage

    HAVING is used to filter groups based on aggregate functions like SUM.
  2. Step 2: Check query syntax and order

    SELECT store, SUM(sales) FROM sales_data GROUP BY store HAVING SUM(sales) > 1000; correctly uses GROUP BY first, then HAVING with SUM(sales) > 1000.
  3. Final Answer:

    SELECT store, SUM(sales) FROM sales_data GROUP BY store HAVING SUM(sales) > 1000; -> Option C
  4. Quick Check:

    Filter groups by aggregate = HAVING [OK]
Quick Trick: HAVING filters aggregates after GROUP BY [OK]
Common Mistakes:
MISTAKES
  • Using WHERE with aggregate functions
  • Placing HAVING before GROUP BY
  • Filtering rows instead of groups

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes