Aggregate functions perform a calculation across a set of rows and return a single summary value. They are most often combined with GROUP BY to summarize rows within categories, but can also run over an entire result set with no grouping at all.
To find the total and average salary per department, you group employees by department_id and apply SUM(salary) and AVG(salary) to each group in a single query.
SELECT department_id,
COUNT(*) AS emp_count,
SUM(salary) AS total_salary,
AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id;A concise interview answer is
Aggregate functions like COUNT, SUM, AVG, MIN, and MAX collapse multiple rows into a single summary value, typically per group when combined with GROUP BY. A key gotcha is that they ignore NULLs in their target column, except COUNT(*), which counts every row regardless of NULLs.
Last updated: 16 July 2026
Previous question: What is a user-defined function, and how do you create one in MySQL?
Next question: What is the difference between the WHERE and HAVING clauses?