The GROUPING SETS Operator

The GROUP BY clause has been part of the SELECT statement syntax since the earliest dialects of T-SQL. You use GROUP BY to create queries that collapse multiple rows belonging to the same group into a single summary row and perform aggregate calculations (such as SUM and AVG) across the individual rows of each group. SQL Server 6.5 later extended the GROUP BY clause by adding the WITH CUBE and WITH ROLLUP operators. These operators perform additional grouping and aggregation of data in standard relational queries, similar to what is provided by online analytical processing (OLAP) queries that slice and dice your data into Analysis Services cubes, but without ever leaving the relational database world. SQL Server 2008 ...

Get Programming Microsoft® SQL Server® 2012 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.