T-SQL » Functions

When it is desired to summarize data within a table, an aggregate query can be created. An aggregate query is an SQL statement that uses an aggregate function to gather information from multiple rows. An aggregate function is a function that performs calculations on a column in a set of rows. When this query is executed, a result set with the summary information is produced in a single row.

An example of when an aggregate function could be used would be to produce a total value of an inventory. This would be accomplished with the SUM function being applied to a price column.

The following aggregate functions are available:

Aggregate Function Description
AVG Average of values in a column.
COUNT Counts how many rows.
MAX Maximum value in a column.
MIN Minimum value in a column.
STDEV Sample standard deviation of the values in a column.
STDEVP Standard deviation of the values in a column.
SUM Adds the values in a column.
VAR Sample variance of the values in a column.
VARP Variance of the values in a column.