Skip to content

Latest commit

 

History

History
57 lines (49 loc) · 3.01 KB

File metadata and controls

57 lines (49 loc) · 3.01 KB

title: "Aggregate Functions (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "01/16/2018" ms.prod: "sql" ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.service: "" ms.component: "t-sql|functions" ms.reviewer: "" ms.suite: "sql" ms.technology:

  • "database-engine" ms.tgt_pltfrm: "" ms.topic: "language-reference" dev_langs:
  • "TSQL" helpviewer_keywords:
  • "functions [SQL Server], aggregate"
  • "aggregate functions [SQL Server], about aggregate functions"
  • "summarizing functions"
  • "aggregate functions [SQL Server]" ms.assetid: 0c06ae42-eb0a-4d77-9d74-aa1e7f344009 caps.latest.revision: 30 author: "edmacauley" ms.author: "edmaca" manager: "craigg" ms.workload: "Active" monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || = sqlallproducts-allversions"

Aggregate Functions (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-all-md]

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. The OVER 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.

[!INCLUDEtsql] provides the following aggregate functions:

AVG MIN
CHECKSUM_AGG SUM
COUNT STDEV
COUNT_BIG STDEVP
GROUPING STRING_AGG
GROUPING_ID VAR
MAX VARP

See also

Built-in Functions (Transact-SQL)
OVER Clause (Transact-SQL)