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.
|AVG()||It returns the average value of an expression.
SELECT AVG(Salary) AS AverageSalary FROM tblEmployees;
|COUNT()||It returns the number of records returned by a select query.
SELECT COUNT(ID) AS NoOfEmployees FROM tblEmployees;
|MAX()||It returns the maximum value in a set of values.
SELECT MAX(Salary) AS HighestSalary FROM tblEmployees;
|MIN()||It returns the minimum value in a set of values.
SELECT MIN(Salary) AS SmallestSalary FROM tblEmployees;
|SUM()||It calculates the sum of a set of values.
SELECT SUM(Salary) AS TotalSalary FROM tblEmployees;
Also, check How To Get Second Highest Salary Using Query In SQL
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