Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Employees Per Department Query
00:00
5 left

Employees Per Department Query

EasySQL · PostgreSQL

Problem

Auto-Owners Insurance maintains department and employee records for internal workforce reporting. Write a PostgreSQL query that returns the total number of employees assigned to each department.

Requirements

  1. Include every department, including departments with no matching employees.
  2. Count employees per department using an aggregation.
  3. Sort results by employee count descending, then department name ascending for ties.

Schema

departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)Department name
employees
ColumnTypeDescription
employee_idPKINTUnique employee identifier
employee_nameVARCHAR(100)Employee's name
department_idINTAssigned department identifier
employment_statusVARCHAR(20)Current employment status
Tablesdepartmentsemployees
Interviewer

Your question is Employees Per Department Query. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.