ROLLUP
and CUBE
Operator Syntax Changes
The ROLLUP
and CUBE
operators produce additional aggregate groupings and are appended to the GROUP B
Y clause. Prior to SQL Server 2008, to include ROLLUP
or CUBE
groupings, you had to specify the WITH ROLLUP
or WITH CUBE
options in the GROUP BY
clause after the list of grouping columns. In SQL Server 2008, the syntax now follows the ANSI standard for ROLLUP
and CUBE
; you first designate the ROLLUP
or CUBE
option and then provide the grouping columns to these operators as a comma-separated list enclosed in parentheses. The new syntax is
GROUP BY [ROLLUP | CUBE ( non-aggregate_column_list ) ]
Following are examples using the pre-2008 syntax:
An example of the new ANSI standard syntax supported in SQL Server ...
Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.