Bird
0
0

Given the table sales with columns region, product, and amount, what will be the output of this query?

medium📝 query result Q4 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Given the table sales with columns region, product, and amount, what will be the output of this query?
SELECT region, SUM(amount) FROM sales GROUP BY region;
ASum of amounts for each product
BSum of amounts for each region
CSum of amounts for each region and product
DTotal sum of all amounts without grouping
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the GROUP BY clause

    The query groups rows by region, so aggregation applies per region.
  2. Step 2: Understand the aggregation function

    SUM(amount) calculates the total amount for each group, here each region.
  3. Final Answer:

    Sum of amounts for each region -> Option B
  4. Quick Check:

    GROUP BY region with SUM = sum per region [OK]
Quick Trick: GROUP BY column aggregates per group [OK]
Common Mistakes:
  • Confusing grouping by product instead of region
  • Expecting total sum without grouping
  • Grouping by multiple columns when only one is specified

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes