| title | Aggregate Functions (Transact-SQL) | ||||
|---|---|---|---|---|---|
| description | An aggregate function in Transact-SQL performs a calculation on a set of values, and returns a single value. Learn about the aggregate functions in the SQL Database Engine. | ||||
| author | markingmyname | ||||
| ms.author | maghan | ||||
| ms.date | 03/17/2026 | ||||
| ms.service | sql | ||||
| ms.subservice | t-sql | ||||
| ms.topic | reference | ||||
| ms.custom |
|
||||
| helpviewer_keywords |
|
||||
| dev_langs |
|
||||
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric || =fabric-sqldb |
[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw-fabricsqldb]
An aggregate function in the Microsoft SQL Database Engine performs a calculation on a set of values, and returns a single value. Except for COUNT(*), aggregate functions ignore NULL values. Aggregate functions are often used with the GROUP BY clause of the SELECT statement.
All aggregate functions are deterministic. In other words, aggregate functions return the same value each time that they are called, when called with a specific set of input values. See Deterministic and nondeterministic functions for more information about function determinism. The OVER clause might follow all aggregate functions, except the STRING_AGG, GROUPING, or GROUPING_ID functions.
Use aggregate functions as expressions only in the following situations:
- The select list of a
SELECTstatement (either a subquery or an outer query). - A
HAVINGclause.
[!INCLUDEtsql] provides the following aggregate functions: