Last Updated: May 3, 2026
GROUP BY produces one row per group, which is perfect when you need totals by country or counts by genre. But reporting often demands more: subtotals for each country, a grand total across everything, or several different grouping perspectives in a single result set.
Writing separate GROUP BY queries and combining them with UNION ALL works, but it's verbose and hard to maintain. ROLLUP, CUBE, and GROUPING SETS solve this by generating multiple levels of aggregation in one pass.