GROUPING()

Indicates whether a specified column expression in a GROUP BY list is aggregated or not. GROUPING returns 1 for aggregated or 0 for not aggregated in the result set. GROUPING can be used only in the SELECT \<select> list, HAVING, and ORDER BY clauses when GROUP BY is specified.

Signature

GROUPING ( <column_expression> )

Examples

SELECT region, GROUPING(region) AS is_total, SUM(amount) AS total FROM dbo.orders GROUP BY ROLLUP (region) ORDER BY is_total, region;
region               is_total total
-------------------- -------- ----------------------------------------
east                        0                                   453.00
north                       0                                   268.50
south                       0                                   126.75
NULL                        1                                   848.25

Run against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.

Available on

  • SQL Server 2017 and later
  • Azure SQL Database
  • Azure SQL Managed Instance
  • Azure Synapse Analytics
  • Azure SQL Edge
  • Microsoft Fabric warehouse
  • Fabric SQL database

Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.