Chapter 10

Aggregating, Windowing, and Ranking Data

In This Chapter

Understanding Basic Aggregations

Using SQL Server Aggregation Functions

Customizing Aggregation Sets

Understanding Windowing

Ranking Functions

Information is the foundation of most organizational decisions. In its raw form, that data is meaningless and offers little value to an information wonk or data analyst; not until the data is summarized or grouped is it considered useful information. Although summarization and analysis can certainly be performed with other tools, such as Reporting Services, Analysis Services, PowerPivot, or an external tool such as SAS, SQL is a set-based language, and a fair amount of summarizing and grouping can be performed well within the SQL SELECT statement.

SQL excels at calculating sums, max values, and averages for the entire data set or for segments of data. In addition, the product of SQL queries can be as simple as a table to a complex pivot table that includes subtotals and totals. In this chapter you explore different ways to group, gather, and summarize data within SQL Server.

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