Working with Aggregate Functions

All the functions you learned about yesterday are row-based: The function acts only on columns in the current row. Aggregate functions act on a set of rows. What are aggregate functions? You probably know them better as the summary, average, minimum, maximum, and count functions. "To aggregate" means to collect or to bring together. So, aggregate functions gather together data from many rows and report it in a single row (see Figure 4.1).

Figure 4.1. Aggregate functions gather values from many rows in a table into a single row in the result set.

SQL Server supports six aggregate functions:

  • SUM()—Total of all values; ...

Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.