Skip to main content

How are aggregate functions related to GROUP BY?

Aggregate functions and GROUP BY work as a pair.

  • Aggregate functions (COUNT, SUM, AVG, MIN, MAX) process several rows and produce one value.
  • GROUP BY splits the table into groups of rows that share the same values in the chosen columns.

When used together: GROUP BY forms the groups -> aggregate functions compute a result for each group.

Example

sql
SELECT department, SUM(salary) FROM employees GROUP BY department;

GROUP BY forms groups by department, and SUM() computes the salary total in each department separately.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.