Grouping with GROUP BY
GROUP BY groups rows together for aggregate calculations.
Count employees per department:
Average salary per department:
Rule: Every column in SELECT must be either:
- In
GROUP BY, or - Inside an aggregate function (
COUNT,SUM, etc.)
Check your understanding
Count how many employees are in each department.
Examples run on the employees sample database. Open any of them in the playground to experiment.