Bird
0
0

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

medium📝 query result Q13 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) FILTER (WHERE amount > 100) AS big_sales FROM sales GROUP BY region;
ASum of all sales amounts per region.
BCount of sales with amount greater than 100 per region.
CSum of sales amounts less than or equal to 100 per region.
DSum of sales amounts greater than 100 per region.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the FILTER condition in SUM

    The FILTER clause limits the SUM to only rows where amount > 100.
  2. Step 2: Analyze the GROUP BY effect

    The query groups rows by region, then sums only amounts above 100 in each group.
  3. Final Answer:

    Sum of sales amounts greater than 100 per region. -> Option D
  4. Quick Check:

    SUM with FILTER (WHERE amount > 100) = sum of big sales [OK]
Quick Trick: FILTER limits rows inside SUM to amount > 100 [OK]
Common Mistakes:
  • Thinking it sums all amounts, ignoring FILTER
  • Confusing SUM with COUNT
  • Ignoring GROUP BY effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes