Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Departments by Call Volume

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

Your question is Top Departments by Call Volume. 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

NJM Insurance Group wants to identify which departments handled the most calls during the previous calendar quarter. Write a PostgreSQL query that ranks departments by the number of calls received in that period.

Requirements

  1. Define the last quarter as the complete calendar quarter immediately before the anchored reference date of August 29, 2026.
  2. Count calls by department, excluding calls outside the last quarter and calls that do not reference a department.
  3. Return the top three departments, including department name and call volume.
  4. Break ties consistently by ordering department ID ascending after call volume descending.

Output

  1. Return one row per selected department with columns department_name and call_volume.
  2. Include only calls from April 1 through June 30, 2026. Calls with NULL or unmatched department IDs are excluded.
  3. Return the top three departments, ordered by call volume descending and department name ascending.
  4. Departments with no qualifying calls remain eligible with a count of zero, but are not expected in the top three.

Schema

departments
ColumnTypeDescription
department_idPKINTUnique department identifier
department_nameVARCHAR(100)NJM department name
calls
ColumnTypeDescription
call_idPKINTUnique call identifier
department_idINTDepartment handling the call
started_atTIMESTAMPCall start timestamp
call_typeVARCHAR(50)Type of customer call
channelVARCHAR(30)Call intake channel
statusVARCHAR(30)Call status
Tablesdepartmentscalls
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results