Weekly Handle Time and First Contact Resolution per Agent

Last updated: November 29, 2026

Quick Overview

Given a conversations table (conversation_id, agent_id, customer_id, started_at, ended_at), write SQL that reports per agent per week the conversation count, average handle time, and first contact resolution rate, where a contact is resolved if the same customer does not contact again within 7 days.

Cresta
Data Manipulation (SQL/Python)
Data Scientist
Cresta
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given a conversations table (conversation_id, agent_id, customer_id, started_at, ended_at), write SQL that reports per agent per week the conversation count, average handle time, and first contact resolution rate, where a contact is resolved if the same customer does not contact again within 7 days.

Cresta sells against business outcomes like lower handle time and higher resolution, so its data scientists compute these KPIs constantly for customer reviews and impact reports. The interviewer checks window functions, a correct FCR definition, and awareness of right-censoring for recent conversations.

What the Interviewer Expects
  • Use LEAD over customer partitions to find the next contact
  • Compute handle time from timestamps, excluding conversations that have not ended
  • Bucket by week with date_trunc
  • Exclude conversations younger than 7 days from the FCR denominator
  • Explain tie-breaking when two conversations share a start time
Key Topics to Cover
Window functions
Contact center KPIs
Right censoring
Date bucketing
Postgres
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you attribute a repeat contact that was handled by a different agent?
  • How would you change the query if transfers create several conversation rows for one contact?
  • How would you show whether an agent's FCR is significantly different from the team?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

One row per conversation; a transfer is assumed to be a separate row. ended_at is null for live calls. Week starts Monday. FCR: a conversation counts as resolved if the next conversation from the sa...

Approach

Compute per row handle seconds and the customer's next started_at with LEAD. Then aggregate by agent and week. For FCR, only conversations at least 7 days old are eligible, because a call from yes...


Submit Your Answer
Markdown supported

Related Questions