Bird
0
0

Consider the table sales with columns region, product, and amount. What will the following query return?

medium📝 query result Q4 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Consider the table sales with columns region, product, and amount. What will the following query return?
SELECT region, product, SUM(amount) FROM sales GROUP BY ROLLUP(region, product);
ASum of amounts grouped only by product
BSum of amounts without any grouping
CSum of amounts grouped by region with no subtotals
DSum of amounts grouped by region and product, plus subtotals by region and a grand total
Step-by-Step Solution
Solution:
  1. Step 1: Understand ROLLUP with two columns

    ROLLUP(region, product) groups by (region, product), then by region only, then grand total.
  2. Step 2: Analyze query result

    The query returns sums for each region-product pair, subtotals per region, and a grand total row.
  3. Final Answer:

    Sum of amounts grouped by region and product, plus subtotals by region and a grand total -> Option D
  4. Quick Check:

    ROLLUP(region, product) = detailed + subtotals + total [OK]
Quick Trick: ROLLUP adds subtotals from right to left grouping [OK]
Common Mistakes:
  • Ignoring subtotals and grand total rows
  • Thinking grouping is only by product
  • Assuming no grouping happens

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes