SQL JOIN

Back to home
Logicmojo - Updated Aug 28, 2021



What are Aggregate Functions?

An aggregate function in database administration is a function that groups the values of several rows as input on specified criteria to generate a single value with more meaningful meaning.

Various Aggregate Functions

🚀 COUNT()

🚀 SUM()

🚀 AVG()

🚀 MIN()

🚀 MAX()


Let's discuss them one by one in brief,

COUNT() function

The COUNT() function returns the number of rows that meet a given set of criteria.


Syntax :

SELECT COUNT(column_name)
FROM table_name
WHERE condition;

Let's understand this by taking one example,


Query :

SELECT COUNT(Salary)
FROM Employee
WHERE (Salary>30000);


Output

3


SUM() function

The SUM() function returns the total sum of a numeric column.


Syntax :

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Let's understand this by taking one example,


Query :

SELECT SUM(Salary)
FROM Employee
WHERE (Salary>30000);


Output

129,000


AVG() function

The AVG() function returns the average value of a numeric column.


Syntax :

SELECT AVG(column_name)
FROM table_name
WHERE condition;

Let's understand this by taking one example,


Query :

SELECT AVG(Salary)
FROM Employee
WHERE (Salary>30000);


Output

43,000


MIN() function

The MIN() function returns the minimum value of a numeric column.


Syntax :

SELECT MIN(column_name)
FROM table_name
WHERE condition;

Let's understand this by taking one example,


Query :

SELECT MIN(Salary)
FROM Employee


Output

18,000


MAX() function

The MAX() function returns the maximum value of a numeric column.


Syntax :

SELECT MAX(column_name)
FROM table_name
WHERE condition;

Let's understand this by taking one example,


Query :

SELECT MAX(Salary)
FROM Employee


Output

51,000



With this article at Logicmojo, you must have the complete idea of SQL Aggregate Functions.