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’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.
Using the tables below, write a SQL query that returns daily agent performance for a given date range.
Return one row per agent per day for calls that started in the date range ['2024-01-01', '2024-01-02'] (inclusive), with:
agent_id, agent_name, call_date (date of call_start_ts)calls_handled: count of calls where the agent was the primary handleranswered_calls: count of handled calls with answer_ts IS NOT NULLavg_talk_seconds: average of (end_ts - answer_ts) in seconds for answered calls (exclude NULLs)total_handle_seconds: sum of (end_ts - call_start_ts) in seconds for handled calls (includes wrap-up)sla_answered_within_20s: percent of answered calls where (answer_ts - call_start_ts) <= 20 seconds (0–100, rounded to 2 decimals)daily_rank_by_calls: rank agents within each day by calls_handled descending (ties share rank)Additional notes:
end_ts is NULL (still in progress).agent_call_leg.is_primary = TRUE to attribute a call to a single agent.avg_talk_seconds should be NULL and sla_answered_within_20s should be 0.| Column | Type | Description |
|---|---|---|
| agent_idPK | INT | Unique agent identifier |
| agent_name | VARCHAR(100) | Agent display name |
| hire_date | DATE | Date the agent was hired |
| site | VARCHAR(50) | Agent site/location |
| Column | Type | Description |
|---|---|---|
| call_idPK | BIGINT | Unique call identifier |
| queue_name | VARCHAR(50) | Queue/routing group name |
| call_start_ts | TIMESTAMP | Timestamp when call entered the system |
| answer_ts | TIMESTAMP | Timestamp when call was answered; NULL if abandoned |
| end_ts | TIMESTAMP | Timestamp when call ended; NULL if still in progress |
| disposition | VARCHAR(30) | Call outcome (e.g., resolved, escalated, abandoned) |
| Column | Type | Description |
|---|---|---|
| call_idPK | BIGINT | Call identifier (FK to calls) |
| agent_idPK | INT | Agent identifier (FK to agents) |
| is_primary | BOOLEAN | Whether this agent is the primary handler for the call |
| leg_start_ts | TIMESTAMP | Timestamp when the agent leg started |
| leg_end_ts | TIMESTAMP | Timestamp when the agent leg ended |