Aggregate functions in SQL perform calculations on a set of values and return a single value. They are often used in conjunction with the GROUP BY
clause to summarize data.
Common Aggregate Functions
- COUNT: Returns the number of rows in a group.
- SUM: Calculates the sum of values in a group.
- AVG: Computes the average of values in a group.
- MIN: Returns the minimum value in a group.
- MAX: Returns the maximum value in a group.
Example
SELECT COUNT(*), SUM(salary), AVG(age)
FROM employees;
This query calculates the count of employees, total salary, and average age across all employees.
Aggregate functions are powerful tools in SQL for summarizing and analyzing data, providing valuable insights into your datasets.