Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Contact Center Agent Performance Metrics

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Contact Center Agent Performance Metrics. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

Business Context

You’re working with the analytics team for a large B2C fintech (tens of millions of customers) that runs a 24/7 contact center. Leadership is rolling out a new agent coaching program and needs a reliable, queryable model to track agent performance and call duration across queues (e.g., billing, fraud, onboarding). Because the company is regulated, the model must support auditability (who handled what call, when, and what the outcome was) and consistent KPI definitions.

The data warehouse receives call events from the telephony system and agent roster updates from HR. Your job is to validate that the data model supports common reporting and then write a query that produces a daily performance rollup.

Task

Using the tables below, write a SQL query that returns daily agent performance for a given date range.

Requirements

Return one row per agent per day for calls that started in the date range ['2024-01-01', '2024-01-02'] (inclusive), with:

  1. agent_id, agent_name, call_date (date of call_start_ts)
  2. calls_handled: count of calls where the agent was the primary handler
  3. answered_calls: count of handled calls with answer_ts IS NOT NULL
  4. avg_talk_seconds: average of (end_ts - answer_ts) in seconds for answered calls (exclude NULLs)
  5. total_handle_seconds: sum of (end_ts - call_start_ts) in seconds for handled calls (includes wrap-up)
  6. sla_answered_within_20s: percent of answered calls where (answer_ts - call_start_ts) <= 20 seconds (0–100, rounded to 2 decimals)
  7. daily_rank_by_calls: rank agents within each day by calls_handled descending (ties share rank)

Additional notes:

  • Ignore calls where end_ts is NULL (still in progress).
  • Use agent_call_leg.is_primary = TRUE to attribute a call to a single agent.
  • If an agent handled calls but none were answered, avg_talk_seconds should be NULL and sla_answered_within_20s should be 0.

Schema

agents
ColumnTypeDescription
agent_idPKINTUnique agent identifier
agent_nameVARCHAR(100)Agent display name
hire_dateDATEDate the agent was hired
siteVARCHAR(50)Agent site/location
calls
ColumnTypeDescription
call_idPKBIGINTUnique call identifier
queue_nameVARCHAR(50)Queue/routing group name
call_start_tsTIMESTAMPTimestamp when call entered the system
answer_tsTIMESTAMPTimestamp when call was answered; NULL if abandoned
end_tsTIMESTAMPTimestamp when call ended; NULL if still in progress
dispositionVARCHAR(30)Call outcome (e.g., resolved, escalated, abandoned)
agent_call_leg
ColumnTypeDescription
call_idPKBIGINTCall identifier (FK to calls)
agent_idPKINTAgent identifier (FK to agents)
is_primaryBOOLEANWhether this agent is the primary handler for the call
leg_start_tsTIMESTAMPTimestamp when the agent leg started
leg_end_tsTIMESTAMPTimestamp when the agent leg ended
Tablesagentscallsagent_call_leg
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results