B, (D,E), & (ROLLUP(A,C)),
it computes the requested aggregates for the following combinations of columns:
-
Group B:
{ B }- uniqueBvalues
-
Group (D,E):
{ DE}- uniqueD Epairs
-
Group ROLLUP(A,C):
{A C }- uniqueA Cpairs{A }- uniqueAvalues{ }- all values
options map of the /aggregate/groupby endpoint.
It is also available via the SQL GROUPING SETS function.
Be mindful that grouping sets is an expensive operation.
Grouping and Nulls
If using the grouping sets operation with a column that contains null values, it may not be apparent which aggregations pertain to the column’s null values and which pertain to all the column’s values, as both will be represented bynull in the result set. To avoid this confusion,
it’s recommended to use the GROUPING()
function to make a distinction between null values in the data and null
grouping values generated by the grouping sets operation. There will be an
example of this below.
Examples
The following request will aggregate the average opening stock price for these groups:- Each market sector
- Each stock symbol
- All sectors and symbols
Limitations
- The maximum number of dimensions that can be computed is 256; the maximum number of columns that can be aggregated is 61
- The column(s) used in the grouping sets operation must be listed as columns
in the
column_namesparameter - As the grouping sets operation is executed via /aggregate/groupby, all Aggregation Limitations also apply