Bird
0
0

Given the table sales with columns region and amount, what will this query return?

medium📝 query result Q4 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Given the table sales with columns region and amount, what will this query return?
SELECT region, SUM(amount) FROM sales GROUP BY region HAVING SUM(amount) > 1000;
ARegions with total sales less than or equal to 1000
BSyntax error due to HAVING clause
CRegions with total sales greater than 1000
DAll regions regardless of sales
Step-by-Step Solution
Solution:
  1. Step 1: Understand GROUP BY and SUM

    The query groups rows by region and sums the amount for each group.
  2. Step 2: Apply HAVING filter

    HAVING filters groups where the sum is greater than 1000.
  3. Final Answer:

    Regions with total sales greater than 1000 -> Option C
  4. Quick Check:

    HAVING filters groups with SUM(amount) > 1000 = D [OK]
Quick Trick: HAVING filters groups after aggregation, not individual rows [OK]
Common Mistakes:
  • Thinking HAVING filters rows before grouping
  • Assuming all regions are returned
  • Believing HAVING causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes