What does GROUP BY do?
GROUP BY groups rows that share the same values in the specified columns,
so you can apply aggregate functions (COUNT, SUM, AVG, and so on) to each group separately.
Example
sql
SELECT department, AVG(salary)
FROM employees
GROUP BY department;The data gets grouped by department,
and the average salary is computed for each department.
Without GROUP BY, aggregate functions run over the whole table;
with it, they run on each group of values.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.