Aggregate functions

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:

  1. COUNT
  2. SUM
  3. AVG
  4. MAX
  5. MIN

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);
about author

admin

salmansrabon@gmail.com

If you like my post or If you have any queries, do not hesitate to leave a comment.

Leave a Reply

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