Example: Semantically Identical Grouping Sets Specifications and Their Resolution - Advanced SQL Engine - Teradata Database

SQL Data Manipulation Language

Product
Advanced SQL Engine
Teradata Database
Release Number
17.00
Published
September 2020
Language
English (United States)
Last Update
2021-01-23
dita:mapPath
qtb1554762060450.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1146
lifecycle
previous
Product Category
Teradata Vantage™

The following three queries return the same results set because they are semantically identical.

     SELECT y,m,r, SUM(u)
     FROM test
     GROUP BY CUBE(y,m), CUBE(r)
     ORDER BY 1,2,3;

     SELECT y,m,r,SUM(u)
     FROM test
     GROUP BY CUBE(y,m,r)
     ORDER BY 1,2,3;

     SELECT y,m,r,SUM(u)
     FROM test
     GROUP BY GROUPING SETS(y,()), GROUPING SETS(m,()),
              GROUPING SETS(r,())
     ORDER BY 1,2,3;

The following three queries return the same results set because they are semantically identical.

     SELECT y, m, r, s, SUM(u)
     FROM test
     GROUP BY ROLLUP(y,m),ROLLUP(r,s)
     ORDER BY 1,2,3,4;

     SELECT y, m, r, s, SUM(u)
     FROM test
     GROUP BY GROUPING SETS((y, m),(),y),ROLLUP(r,s)
     ORDER BY 1,2,3,4;

     SELECT y, m, r, s, SUM(u)
     FROM test
     GROUP BY GROUPING SETS((y,m),(),y),GROUPING SETS((),r,(r,s))
     ORDER BY 1,2,3,4;