Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL: Count Employees by Department

EasySQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL: Count Employees by Department. Start with the requirements and the one table on the right.

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.

Problem

Kovai's employee directory needs a department-level headcount for workforce reporting. Write a PostgreSQL query that counts employees in each department from the employees table.

Requirements

  1. Return one row per department with the department name and employee count.
  2. Include employees whose department is not assigned under the label Unassigned.
  3. Sort the results alphabetically by department label.

Schema

employees
ColumnTypeDescription
employee_idPKINTEGERUnique employee identifier
employee_nameVARCHAR(100)Employee's full name
department_nameVARCHAR(100)Employee's department
Tablesemployees
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results