Search⌘ K
AI Features

Aggregate Functions

Explore the use of aggregate functions in T-SQL to compute averages, counts, minimums, maximums, and sums over multiple rows. Understand how to apply these functions correctly in SELECT statements, and learn the differences between COUNT variations and the proper use of aggregate expressions.

An aggregate function is a function that takes in multiple values and returns a single value. It can be viewed as a function that performs an operation over the values of multiple rows.

In T-SQL, we have these aggregate functions:

  • AVG(): Returns the average of supplied values
  • COUNT(): Returns the number of rows
  • MIN(): Returns the minimum value
  • MAX(): Returns the maximum value
  • SUM(): Returns the sum

As an argument, all aggregate functions take an expression that returns a range of values. Often, the expression is the name of the column over the values of which we want to perform the operation:

SELECT
...