GROUPING SETS in SQL Server 2008

In my last two posts, I gave examples of aggregation WITH ROLLUP and CUBE.  SQL Server 2008 continues to support this syntax, but also introduces new more powerful ANSI SQL 2006 compliant syntax.  In this post, I’ll give an overview of the changes. First, let’s see how we rewrite simple WITH ROLLUP and CUBE queries…

13

Aggregation WITH CUBE

In my last post, I wrote about how aggregation WITH ROLLUP works.  In this post, I will discuss how aggregation WITH CUBE works.  Like the WITH ROLLUP clause, the WITH CUBE clause permits us to compute multiple “levels” of aggregation in a single statement.  To understand the difference between these two clauses, let’s look at an…

11

Aggregation WITH ROLLUP

In this post, I’m going to discuss how aggregation WITH ROLLUP works.  The WITH ROLLUP clause permits us to execute multiple “levels” of aggregation in a single statement.  For example, suppose we have the following fictitious sales data.  (This is the same data that I used for my series of posts on the PIVOT operator.)…

11