GROUPING
super-aggregate flag
What changes
- Input
- a GROUP BY column
- Output or change
- 1 when the column is rolled up in this row, else 0
- Return type
- tinyint
Syntax at a glance
GROUPING ( <column_expression> )
Work example
Tell whether a grouped column was rolled up in a subtotal row.
Pair GROUPING with ROLLUP, CUBE, or GROUPING SETS and label subtotal rows explicitly.
Check your work A null from rollup can mean an aggregated-away column rather than missing source data.
Open Microsoft Learn for full syntax, permissions, and details for your version.