In a DBMS, aggregation operators are used to perform operations on a group of values to return a single summarizing value. The most common aggregation operators include COUNT, SUM, AVG, MIN, and MAX.
Here are some examples of how you might use these operators:
Returns the number of rows that matches a specified criterion.
SyntaxCOUNT(expression)
SELECT COUNT(*) FROM Employees;
This query would return the total number of rows in the Employees table.
Returns the total sum of a numeric column.
SyntaxSUM(expression)
SELECT SUM(salary) FROM Employees;
This query would return the total sum of the salary column values in the Employees table.
AVG(expression)
SELECT AVG(salary) FROM Employees;
This query would return the average salary from the Employees table.
Returns the smallest value of the selected column.
SyntaxMIN(expression)
SELECT MIN(salary) FROM Employees;
This query would return the lowest salary from the Employees table.
Returns the largest value of the selected column.
SyntaxMAX(expression)
SELECT MAX(salary) FROM Employees;
This query would return the highest salary from the Employees table.
These aggregation operators are often used with the GROUP BY clause to group the result-set by one or more columns. For example, to find the highest salary in each department, you could write:
SELECT department_id, MAX(salary)
FROM Employees
GROUP BY department_id;
This query would return the highest salary for each department in the Employees table.