Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Employee Count Per Department Query

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

Your question is Employee Count Per Department Query. Start with the requirements and the two tables 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

IFS maintains organizational data in emp_tab and dept_tab. Write a PostgreSQL query that reports the number of employees assigned to every department.

Requirements

  1. Return the department name and employee count.
  2. Include departments with zero employees.
  3. Exclude employees whose dept_id does not match a department, while still retaining all departments.
  4. Order the result alphabetically by department name.

Schema

emp_tab
ColumnTypeDescription
nameVARCHAR(100)Employee name
dept_idINTDepartment identifier assigned to the employee
dept_tab
ColumnTypeDescription
dept_idPKINTUnique department identifier
dept_nameVARCHAR(100)Department name
Tablesemp_tabdept_tab
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results