In this article, we will learn how to use the Aggregate Functions in SQL.

An Aggregate Function allows us to perform a calculation on a set of values to return a single scalar value. We often use aggregate functions with the GROUP BY and HAVING clauses of the SELECT statement.

Below is a selection from the “tblEmployees” table:

SELECT * FROM tblEmployees ORDER BY Salary DESC;

The following are the most commonly used SQL Aggregate Functions.

FunctionDescription
AVG()It returns the average value of an expression.

SELECT AVG(Salary) AS AverageSalary FROM tblEmployees;

Output: 19210

COUNT()It returns the number of records returned by a select query.

SELECT COUNT(ID) AS NoOfEmployees FROM tblEmployees;

Output: 5

MAX()It returns the maximum value in a set of values.

SELECT MAX(Salary) AS HighestSalary FROM tblEmployees;

Output: 30000

MIN()It returns the minimum value in a set of values.

SELECT MIN(Salary) AS SmallestSalary FROM tblEmployees;

Output: 10000

SUM()It calculates the sum of a set of values.

SELECT SUM(Salary) AS TotalSalary FROM tblEmployees;

Output: 96050

 

Also, check How To Get Second Highest Salary Using Query In SQL

Subscribe

Select Categories