DBMS Menu


Aggregation Operators in DBMS




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:

COUNT

Returns the number of rows that matches a specified criterion.

Syntax
COUNT(expression) 
Example:
SELECT COUNT(*) FROM Employees; 

This query would return the total number of rows in the Employees table.


SUM

Returns the total sum of a numeric column.

Syntax
SUM(expression) 
Example:
SELECT SUM(salary) FROM Employees;

This query would return the total sum of the salary column values in the Employees table.


AVG

Returns the average value of a numeric column.

Syntax
AVG(expression) 
Example:
SELECT AVG(salary) FROM Employees;

This query would return the average salary from the Employees table.


MIN

Returns the smallest value of the selected column.

Syntax
MIN(expression) 
Example:
SELECT MIN(salary) FROM Employees;

This query would return the lowest salary from the Employees table.


MAX

Returns the largest value of the selected column.

Syntax
MAX(expression) 
Example:
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:

Example:
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.


Next Topic :Complex Integrity Constraints in SQL