Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Employee Count by Department
00:00
5 left

Employee Count by Department

EasySQL · PostgreSQL

Problem

Synchrony needs a workforce report for departments supporting products such as Synchrony Care. Write a PostgreSQL query that counts active employees by department.

Requirements

  1. Return every department, including departments with no active employees.
  2. Count only employees whose is_active value is TRUE.
  3. Return department_name and active_employee_count, ordered alphabetically by department name.

Place the active-employee condition in the join so that departments with no matching active employees remain in the result. Employees without a valid department should not create an additional department row.

Schema

departments
ColumnTypeDescription
department_idPKINTPrimary key for the department
department_nameVARCHAR(100)Department name
employees
ColumnTypeDescription
employee_idPKINTPrimary key for the employee
employee_nameVARCHAR(100)Employee's name
department_idINTAssigned department identifier
is_activeBOOLEANWhether the employee is currently active
Tablesdepartmentsemployees
Interviewer

Your question is Employee Count by Department. 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.