Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Contact Center Agent Performance Metrics
00:00
5 left

Contact Center Agent Performance Metrics

HardSQL · PostgreSQL

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
Interviewer

Your question is Contact Center Agent Performance Metrics. Start with the requirements and the three 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.