1
Jan
Aggregate functions are used to perform calculations on multiple values and return it to as a single column value.
There are 5 types of ISO standard aggregate functions:
COUNT:
Example:
Query to find total rows in table
SELECT COUNT(*) AS Total FROM employees;
SUM
Example:
Query to find total salary in IT department
SELECT SUM(salary) FROM employees WHERE Department='IT';

AVG
Example:
Query to find average salary of IT department:
SELECT AVG(salary) FROM employees WHERE Department='IT';

MAX
Example:
Query to get the max amount of salary:
SELECT MAX(Salary) FROM employees
Query to find who get the max salary in all departments:
SELECT FirstName,LastName,Department,Salary FROM employees WHERE Salary=(SELECT MAX(Salary) FROM employees);

MIN
Example:
Query to find min amount of salary:
SELECT MIN(Salary) FROM employees;
Query to find who get the min salary in all departments:
SELECT FirstName,LastName,Department,Salary FROM employees WHERE Salary=(SELECT MIN(Salary) FROM employees);

Leave a Reply