GROUPING_ID() equivalents
statements #tsql#statements
of ones and zeros.
interprets that string as a base-2 number and returns the
equivalent integer.
For example, consider the following statement:
This table shows the
input and output values.
Each
argument must be an element of the
list.
returns an
integer bitmap whose lowest
n
bits might be
lit. A lit bit indicates the corresponding argument
isn’t a grouping column for the given output row. The lowest-order bit corresponds to
argument
n
, and the
n
-1
lowest-order bit corresponds to argument 1.
For a single grouping query,
is equivalent to
, and both return.
Expand table
th
Statement A
Statement B
GROUPING_ID
GROUPING_ID()
a
100
4 b
010
2 c
001
1 ab
110
6 ac
101
5 bc
011
3 abc
111
7
GROUPING_ID
GROUP BY
GROUPING_ID()
GROUPING (<column_expression>)
GROUPING_ID (<column_expression>)
0
SELECT a, b, c,
SUM (d),
GROUPING_ID (a, b, c)
FROM
T
GROUP
BY
<group_by_list>