GROUP BY

Aggregate rows by a column

Aggregation

SQL

SELECT department, COUNT(*) as count, AVG(salary) as avg_salary
FROM employees
GROUP BY department;

What each clause does

GROUP BY groups rows by department. COUNT(*) counts rows per group. AVG(salary) computes the average salary per department.

Related tools

Other SQL examples