sql_agg - GROUPING
... GROUPING( col )
The result of the grouping function
GROUPING indicates whether a specific column is part of the
GROUPING must be followed by a column name in parentheses as an argument.
The return value of the grouping function
GROUPING has the data type
INT1. The following return values of the grouping function are possible here:
|0||The column is not part of the aggregation.|
|1||The column is part of the aggregation.|
The columns that are part of the aggregation contain the null values as placeholders in the corresponding
results. More specifically , the grouping function
GROUPING determines whether the column that contains a null value in the result was part of the aggregation or whether it was already the null value in the
- The column used as an argument of the grouping function
GROUPINGmust also be added to the
The following example calculates the number of Lufthansa flights by plane type (the column
and by connection (the column
connid). Here, the grouping function for the plane type column or connection column is used to determine whether they are part of the aggregation.
SELECT FROM sflight FIELDS carrid, connid, planetype, COUNT( * ) AS flights_count, grouping( connid ) AS agg_connid, grouping( planetype ) AS agg_planetype WHERE carrid = 'LH' GROUP BY GROUPING SETS ( ( carrid, planetype ), ( carrid, connid ), ( ) ) ORDER BY connid, planetype INTO TABLE @DATA(result_grouping). cl_demo_output=>display( result_grouping ).