Aggregate Functions

Learn about SQL functions that take multiple values as input.

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 AVG(ColumnName) AS Average
FROM TableSchema.TableName;

The AVG() and SUM() functions accept only numeric columns, while MIN(), MAX(), and COUNT() functions can accept numbers, text, and datetime columns.

Calculate the average

If we supply a range of numeric values, the AVG() returns the average. We often use the AVG() function to calculate the average of a particular column. Let’s calculate the average grade of students:

Get hands-on with 1200+ tech skills courses.