SQL: Employee Count by Department
Medium
SQL — Aggregation
SQL
GROUP BY
COUNT
Count employees in each department.
Constraints
Write standard SQL (MySQL 8.0 compatible).
Examples
Example 1:
Input: dept_id name
1 Ahmed
1 Sara
2 Omar
Output:
Example 2:
Input: dept_id name
1 Ahmed
1 Sara
2 Omar
Output:
Hints
GROUP BY department with COUNT.
Tests:
Runtime:
Memory:
Test
Input:
Expected:
Got:
Click Run Code to test against sample cases, or Submit to test against all cases.
▲ Console