Aggregate functions perform a calculation on a set of values and return a single value. Except for COUNT, aggregate functions ignore null values. Aggregate functions are frequently used with the GROUP BY clause of the SELECT statement.
All aggregate functions are deterministic. This means aggregate functions return the same value any time that they are called by using a specific set of input values. For more information about function determinism, see Deterministic and Nondeterministic Functions. TheOVER clause may follow all aggregate functions except GROUPING and GROUPING_ID.
Aggregate functions can be used as expressions only in the following:
- The select list of a SELECT statement (either a subquery or an outer query).
- A HAVING clause.
Transact-SQL provides the following aggregate functions: