- Categories:
Aggregate functions (General)
GROUPING_ID¶
Describes which of a list of expressions are grouped in a row produced by a GROUP BY query.
Alias for GROUPING.
Syntax¶
Usage notes¶
GROUPING_ID 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_ID(
expr) returns 0 for a row that is grouped onexpr, and 1 for a row that is not grouped onexpr.GROUPING_ID(
expr1,expr2, … ,exprN) returns the integer representation of a bit-vector containing GROUPING_ID(expr1) , GROUPING_ID(expr2) , … , GROUPING_ID(exprN).
Examples¶
The examples use the following table and data:
This example groups on col_x. Calling GROUPING_ID(col_x) returns 0, indicating that col_x is indeed one of
the grouping columns.
This query groups by sets: