Coding question · Basic Filter AggEasyAsked at Amazon

Headcount by department

JOIN + GROUP BY + COUNT.

Back to all coding questions

The Brief

HR AnalyticsCHRO's office#coding-interview

Return the department name and employee count for each department that has employees. Columns: `department_name`, `headcount`. Order by department name. Tables: `ci_employees`, `ci_departments`.

Tables & columns available

ci_employeesdim6 columns
ColumnTypeKey
idINTPK
nameTEXT
department_idINTFK → ci_departments.id
manager_idINTFK → ci_employees.id
salaryINT
hire_dateDATE
ci_departmentsdim2 columns
ColumnTypeKey
idINTPK
nameTEXT

Hints (2)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

JOIN ci_employees to ci_departments on department_id.

Hint 2

GROUP BY the department name.