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 valuesCOUNT()
: Returns the number of rowsMIN()
: Returns the minimum valueMAX()
: Returns the maximum valueSUM()
: 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 1400+ tech skills courses.