v.22.6New Feature
Add GROUPING Function for Disambiguation in ROLLUP, CUBE, and GROUPING SETS
AddGROUPINGfunction. It allows to disambiguate the records in the queries withROLLUP,CUBEorGROUPING SETS. Closes #19426. #37163 (Dmitry Novik).
Why it matters
TheGROUPING function addresses the challenge of disambiguating aggregated rows generated by grouping extensions like ROLLUP, CUBE, and GROUPING SETS. This helps users to identify which columns are aggregated and which are present as is, improving analysis and clarity in complex grouped query results.How to use it
Use theGROUPING function in your SELECT statements alongside ROLLUP, CUBE, or GROUPING SETS clauses. For example:SELECT
city,
country,
<code>GROUPING</code>(city) AS city_grouping,
<code>GROUPING</code>(country) AS country_grouping
FROM table_name
<code>GROUP BY</code> <code>ROLLUP</code>(city, country)This will help identify which rows correspond to which grouping levels.