Aggregate Functions

An aggregate function performs a calculation one or more values and returns a single value. The aggregate function is often used with the GROUP BY clause and HAVING clause of the SELECT statement.


The following table shows the SQL Server aggregate functions:

Aggregate function Description


AVG The AVG() aggregate function calculates the average of non-NULL

values in a set.


CHECKSUM_AGG The CHECKSUM_AGG() function calculates a checksum value

based on a group of rows.


COUNT The COUNT() aggregate function returns the number of rows in a

group, including rows with NULL values.


COUNT_BIG The COUNT_BIG() aggregate function returns the number of rows

(with BIGINT data type) in a group, including rows with NULL values.

MAX The MAX() aggregate function returns the highest value (maximum)

in a set of non-NULL values.


MIN The MIN() aggregate function returns the lowest value (minimum) in

a set of non-NULL values.


STDEV The STDEV() function returns the statistical standard deviation of all

values provided in the expression based on a sample of the data

population.


STDEVP The STDEVP() function also returns the standard deviation for all

values in the provided expression, but does so based on the entire data

population.


SUM The SUM() aggregate function returns the summation of all non-

NULL values a set.


VAR The VAR() function returns the statistical variance of values in an