Bird
0
0

What result does this query produce on the transactions table with columns store and sales?

medium📝 query result Q5 of 15
SQL - GROUP BY and HAVING

What result does this query produce on the transactions table with columns store and sales?

SELECT store, SUM(sales) FROM transactions GROUP BY store HAVING SUM(sales) > 1000;
AStores with total sales less than or equal to 1000
BStores with total sales greater than 1000
CAll stores regardless of sales
DStores with exactly 1000 total sales
Step-by-Step Solution
Solution:
  1. Step 1: Group data by store

    The query groups rows by the store column.
  2. Step 2: Calculate total sales per store

    It sums the sales for each store.
  3. Step 3: Filter groups with HAVING

    The HAVING clause keeps only stores where the sum of sales is greater than 1000.
  4. Final Answer:

    Stores with total sales greater than 1000 -> Option B
  5. Quick Check:

    HAVING filters groups by aggregate conditions [OK]
Quick Trick: HAVING filters groups after aggregation [OK]
Common Mistakes:
MISTAKES
  • Confusing HAVING with WHERE clause
  • Assuming HAVING filters individual rows
  • Misinterpreting the aggregate condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes