Cube and Rollup and Grouping Sets in SQL Server
Cube and Rollup and Grouping Sets in SQL Server
Cube In SQL
CUBE is an aggregate operator that produces a super-aggregate row.
The summary row is displayed for every possible combination of groups in the result set.
In addition to the usual rows provided by the GROUP BY, it also provides the summary
of the rows that the GROUP BY clause generates.
The summary row displays NULL in the result set but at the same time returns all the
values for those.
Cube() in SQL server produces the result set by generating all combinations of columns
specified in GROUP BY CUBE().
Write a query to retrieve Sum of Salary grouped by all possible combinations of the 2
columns (City and Gender) as well as GRAND TOTAL. - Query Given Below In this
Blog
Rollup In SQL Server
In addition to the usual rows that are generated by the GROUP BY clause, it also
introduces summary rows into the result set.
It arranges the groups from the lowest to the highest.
It is similar to CUBE operator but generates a result set that shows groups arranged in a
hierarchical order.
Group hierarchy in the result is dependent on the order in which the columns that are
grouped are specified.
union all
union all
union all