How To Use Aggregate Functions In SQL

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.

Function Description
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

1 Comment

  1. oprolevorter

    I know this if off topic but I’m looking into starting my own blog and was curious what all is required to get setup? I’m assuming having a blog like yours would cost a pretty penny? I’m not very web smart so I’m not 100 positive. Any recommendations or advice would be greatly appreciated. Thank you


Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories