Skip to content

Returns a bit mask indicating which GROUP BY expressions are not included in the current grouping set. Bits are assigned with the rightmost argument corresponding to the least-significant bit; each bit is 0 if the corresponding expression is included in the grouping criteria of the grouping set generating the current result row, and 1 if it is not included.

GROUPING ( expr [, expr, ...] )

Grouping sets items.

UInt32.

select a, b, grouping(a), grouping(b), grouping(a,b), grouping(b,a) from t group by grouping sets ((a,b),(a),(b), ()) ;
┌──────┬──────┬─────────────┬─────────────┬────────────────┬────────────────┐
│ a │ b │ grouping(a) │ grouping(b) │ grouping(a, b) │ grouping(b, a) │
├──────┼──────┼─────────────┼─────────────┼────────────────┼────────────────┤
NULL │ A │ 1021
│ a │ NULL0112
│ b │ A │ 0000
NULLNULL1133
│ a │ A │ 0000
│ b │ B │ 0000
│ b │ NULL0112
│ a │ B │ 0000
NULL │ B │ 1021
└──────┴──────┴─────────────┴─────────────┴────────────────┴────────────────┘