ROLLUP (SQL)
A SQL shortcut within GROUPING SETS that generates hierarchical subtotals. GROUP BY ROLLUP (year, month, day) gives totals per day, per month, per year, and a grand total — perfect for reports with "subtotals and a grand total".
Logic: ROLLUP (a, b, c) produces the groupings (a,b,c), (a,b), (a), and () → it "rolls up" from the finest to the coarsest level. Think of a financial report: amounts per day, summed to month, summed to year, summed to everything. Distinct from CUBE (which gives ALL combinations of dimensions, not just the hierarchical roll-up). Use ROLLUP when the dimensions have a natural hierarchy (time: year > month > day; geography: country > region > city). The GROUPING() function identifies subtotal rows. A SQL standard, widely supported. Saves you from UNIONing together several aggregation queries manually.