What are SQL aggregate functions?
Why Interviewers Ask This
Foundational questions like this help interviewers calibrate the rest of the interview. A confident, accurate answer signals that you have solid MySQL / SQL basics — a prerequisite for any developer role.
Answer
Aggregate functions perform a calculation on a set of rows and return a single value. They are used with SELECT and often with GROUP BY. Key functions: COUNT() — counts rows: COUNT(*) counts all rows including NULLs; COUNT(column) counts non-NULL values in that column; COUNT(DISTINCT column) counts unique non-NULL values; SUM(column) — adds up numeric values (ignores NULLs); AVG(column) — calculates average (ignores NULLs); MAX(column) / MIN(column) — largest/smallest value; GROUP_CONCAT(column) — concatenates values from multiple rows into a single string. Example: SELECT department, COUNT(*) AS employees, AVG(salary) AS avg_salary, MAX(salary) AS highest FROM employees GROUP BY department HAVING COUNT(*) > 5 ORDER BY avg_salary DESC;. Aggregate functions ignore NULL values (except COUNT(*)). They cannot be used in WHERE — use HAVING for filtering aggregated results.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex MySQL / SQL answers easy to follow.