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,
The COUNT() function returns the number of rows that meet a given set of criteria.
SELECT COUNT(column_name) FROM table_name WHERE condition;
Let's understand this by taking one example,
SELECT COUNT(Salary) FROM Employee WHERE (Salary>30000);
3
The SUM() function returns the total sum of a numeric column.
SELECT SUM(column_name) FROM table_name WHERE condition;
Let's understand this by taking one example,
SELECT SUM(Salary) FROM Employee WHERE (Salary>30000);
129,000
The AVG() function returns the average value of a numeric column.
SELECT AVG(column_name) FROM table_name WHERE condition;
Let's understand this by taking one example,
SELECT AVG(Salary) FROM Employee WHERE (Salary>30000);
43,000
The MIN() function returns the minimum value of a numeric column.
SELECT MIN(column_name) FROM table_name WHERE condition;
Let's understand this by taking one example,
SELECT MIN(Salary) FROM Employee
18,000
The MAX() function returns the maximum value of a numeric column.
SELECT MAX(column_name) FROM table_name WHERE condition;
Let's understand this by taking one example,
SELECT MAX(Salary) FROM Employee
51,000