Skip to content

Latest commit

 

History

History
56 lines (47 loc) · 2.81 KB

File metadata and controls

56 lines (47 loc) · 2.81 KB
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
ignite-2025
helpviewer_keywords
functions [SQL Server], aggregate
aggregate functions [SQL Server], about aggregate functions
summarizing functions
aggregate functions [SQL Server]
dev_langs
TSQL
monikerRange >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric || =fabric-sqldb

Aggregate functions (Transact-SQL)

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

[!INCLUDEtsql] provides the following aggregate functions:

Related content