Part 57: Advanced Grouping: ROLLUP for Subtotals and Grand Totals

Part 57 Technology Updated September 12, 2026

Part 57: Advanced Grouping: ROLLUP for Subtotals and Grand Totals

ROLLUP generates hierarchical subtotals and grand totals along an ordered hierarchy.


1. Syntax

SELECT year, quarter, SUM(sales) AS total_sales
FROM quarterly_sales
GROUP BY ROLLUP (year, quarter);

Generates aggregations for: (year, quarter), (year), and () (grand total).


Key Takeaways

  • Use ROLLUP for hierarchical financial and quarterly reporting.

In Part 58, we will explore Advanced Grouping: CUBE for Multi-Dimensional Cross-Tabulation!