O'Reilly logo

Microsoft® SQL Server™ 2000 Programming by Example by Carlos Eduardo Rojas, Fernando G. Guerrero

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The CUBE and ROLLUP Operators

To facilitate the use of summary information in client applications, SQL Server 2000 provides the ROLLUP and CUBE operators.

As you can see in Listing 11.20, using ROLLUP you can get aggregations at different levels in a single result set. Remember that using COMPUTE, you obtain a reportlike result set (see Listing 11.19).

Code Listing 11.20. Use ROLLUP to Produce a Result Set with Aggregations at Different Levels
					 SELECT CategoryName AS Category, ProductName AS Product, SUM((OD.UnitPrice * Quantity * (1-Discount))) AS Price, AVG(Discount) AS AvgDiscount FROM [Order Details] OD JOIN Orders O ON O.OrderID = OD.OrderID ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required