grouping_id() function can be used to determine the level of grouping in a query using
GROUPING SETS or the
ROLLUP operators. Unlike the
GROUPING() function, which takes only a single column expression as an argument and returns a
0 to indicate whether that individual column is being aggregated, the
grouping_id() function accepts multiple column expressions and returns a bitmap to indicate which columns are being aggregated for that row.
SELECT c.CustomerID, c.TerritoryID, sod.ProductID, ...