Bird
0
0

Why does ROLLUP generate fewer subtotal rows than CUBE when used with the same columns?

hard📝 Conceptual Q10 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Why does ROLLUP generate fewer subtotal rows than CUBE when used with the same columns?
AROLLUP creates hierarchical totals by rolling up from right to left, while CUBE creates all possible combinations
BROLLUP filters out NULL values, CUBE does not
CROLLUP only works with numeric columns, CUBE works with all types
DROLLUP sorts the data, CUBE does not
Step-by-Step Solution
Solution:
  1. Step 1: Understand ROLLUP behavior

    ROLLUP generates subtotals in a hierarchical manner, aggregating columns from right to left.
  2. Step 2: Understand CUBE behavior

    CUBE generates subtotals for every possible combination of grouping columns, resulting in more rows.
  3. Final Answer:

    ROLLUP creates hierarchical totals by rolling up from right to left, while CUBE creates all possible combinations -> Option A
  4. Quick Check:

    ROLLUP < CUBE subtotal rows due to hierarchy vs all combos [OK]
Quick Trick: ROLLUP = hierarchical subtotals; CUBE = all combos [OK]
Common Mistakes:
  • Confusing subtotal counts between ROLLUP and CUBE
  • Thinking ROLLUP filters NULLs
  • Assuming ROLLUP only works with numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes