Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Aggregate functions (Transact-SQL)

Applies to: 👁 Image
SQL Server 👁 Image
Azure SQL Database 👁 Image
Azure SQL Managed Instance 👁 Image
Azure Synapse Analytics 👁 Image
Analytics Platform System (PDW) 👁 Image
SQL analytics endpoint in Microsoft Fabric 👁 Image
Warehouse in Microsoft Fabric 👁 Image
SQL database in Microsoft Fabric

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 SELECT statement (either a subquery or an outer query).
  • A HAVING clause.

Transact-SQL provides the following aggregate functions:

Related content


Feedback

Was this page helpful?

Additional resources