Bird
0
0

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

medium📝 query result Q13 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Given the table sales with columns region, product, and amount, what will be the output rows count of this query?
SELECT region, product, SUM(amount) FROM sales GROUP BY ROLLUP(region, product);
ANumber of distinct (region, product) pairs plus one subtotal per region plus one grand total row.
BNumber of distinct (region, product) pairs only.
CNumber of distinct regions only.
DNumber of distinct products only.
Step-by-Step Solution
Solution:
  1. Step 1: Understand ROLLUP output rows

    ROLLUP(region, product) returns all (region, product) groups, plus subtotals per region, plus a grand total row.
  2. Step 2: Count rows

    Total rows = distinct (region, product) + distinct regions (subtotals) + 1 (grand total).
  3. Final Answer:

    Number of distinct (region, product) pairs plus one subtotal per region plus one grand total row. -> Option A
  4. Quick Check:

    ROLLUP adds subtotals and grand total [OK]
Quick Trick: ROLLUP adds subtotals and grand total rows [OK]
Common Mistakes:
  • Ignoring subtotal and grand total rows
  • Counting only distinct pairs
  • Confusing ROLLUP with CUBE output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes