Skip to content

SQL Reference

GROUP BY

SELECT department, COUNT(*)
FROM employees
GROUP BY department;
| department | COUNT(*) |
|------------|----------|
| Finance | 100 |
| HR | 50 |
| IT | 150 |

In this example, the SQL statement groups the ‘employees’ table by the ‘department’ column, and it counts the number of records for each group. The output table therefore shows the number of employees in each department.