Easy JOINsAggregation Free

SQL interview question: Departments With More Than 5 Employees

Large Department Report

The HR team needs a report showing which departments have grown beyond a certain size threshold.

Write a query to identify departments with more than 5 employees. Return department_name and total_employees.

Sort by employee count descending.

Skills: GROUP BY and HAVING clauses

Tables

employees 37 rows
  • id integer PK
  • first_name text
  • last_name text
  • email text
  • department_id integer → departments
  • salary integer
  • hire_date text
  • manager_id integer → employees
  • title text
idfirst_namelast_nameemaildepartment_idsalaryhire_datemanager_idtitle
1AliceChen[email protected]12500002015-01-15NULLCEO
2RobertMartinez[email protected]21800002016-03-20NULLCEO
3SarahJohnson[email protected]11500002017-06-101VP Engineering
departments 5 rows
  • id integer PK
  • name text
  • location text
idnamelocation
1EngineeringSan Francisco
2SalesNew York
3MarketingLos Angeles

Keep going