SQL Flow Field Guide

GROUPING

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

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.