GROUP BY ROLLUP
hierarchical super-aggregates from right to left of the key list; rolled-up keys are NULL
What changes
- Input
- rows after WHERE
- Output or change
- detail groups plus subtotal and grand-total rows
Syntax at a glance
GROUP BY ROLLUP ( column_expression [ ,...n ] )
Work example
A report needs a hierarchy of subtotals from detail rows to a grand total.
Use ordered grouping keys and label subtotal rows with GROUPING. Check each level against a hand total.
Check your work GROUP BY ROLLUP. The detail, parent, and grand-total rows equal the expected hierarchy totals.
Open Microsoft Learn for full syntax, permissions, and details for your version.