Aggregations and Grouping

by Wayne Sheffield

Aggregate functions are used to perform a calculation on one or more values, and the result is a single value. If your query has any columns with nonwindowed aggregate functions, then a GROUP BY clause is required for the query. Table 5-1 shows the various aggregate functions.

Table 5-1. Aggregate Functions

Function Name



The AVG aggregate function calculates the average of non-NULL values in a group.


The CHECKSUM_AGG function returns a checksum value based on a group of rows, allowing you to potentially track changes to a table. For example, adding a new row ...

Get SQL Server T-SQL Recipes, Fourth Edition 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.