GROUPING
functionsupportedCore SQL functionsDescribes which of a list of expressions are grouped in a row produced by a GROUP BY query.
Syntax
supportedpartialnot supportednot scored
GROUPING( <expr1> [ , <expr2> , ... ] )
Usage notes
- GROUPING is not an aggregate function, but rather a utility function that can be used alongside aggregation, to determine the level of aggregation a row was generated for:
- GROUPING(expr) returns 0 for a row that is grouped on expr, and 1 for a row that is not grouped on expr.
- GROUPING(expr1, expr2 , … , exprN) returns the integer representation of a bit-vector containing GROUPING(expr1) , GROUPING(expr2) , … , GROUPING(exprN). The first expression is the most significant bit. For example, GROUPING(col_x, col_y) returns 0 when the row is grouped on both columns, 1 when it is grouped on col_x only, 2 when it is grouped on col_y only, and 3 for the grand total row.
- Use GROUPING to tell apart a NULL that marks a subtotal or grand total row from a NULL that is stored in the data.