Weekly AI Deflection Rate per Customer With Week-over-Week Change

Last updated: November 29, 2026

Quick Overview

Using a conversations table and a handoffs table (one row per escalation to a human, possibly several per conversation), write SQL that returns, for each customer and week, the number of conversations, the share resolved without any human handoff, and the change from the previous week.

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

0

0

0 solved


Using a conversations table and a handoffs table (one row per escalation to a human, possibly several per conversation), write SQL that returns, for each customer and week, the number of conversations, the share resolved without any human handoff, and the change from the previous week.

Deflection (conversations the AI agent finishes without a human) is the number Decagon customers watch most closely, and analysts report it per customer every week. The interviewer is checking that you avoid double counting from a one-to-many join, filter test traffic, and use a window function for the trend.

What the Interviewer Expects
  • States the deflection definition and the grain before writing SQL
  • Avoids inflating counts when a conversation has multiple handoffs
  • Excludes internal test or simulation conversations
  • Uses LAG over a per-customer partition for week-over-week change
  • Casts to decimal so the rate is not integer division
Key Topics to Cover
window functions
LAG
anti-join
date truncation
deflection rate
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 handle a week with zero conversations so LAG compares to the right prior week?
  • Some conversations are abandoned by the user without a handoff. Are those deflected?
  • How would you add a 4-week rolling deflection rate?
  • How would you compare deflection fairly across customers with very different topic mixes?
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

conversations(conversation_id, customer_id, started_at, channel, is_test) has one row per conversation. handoffs(conversation_id, handed_off_at, reason) can have zero, one or several rows per conv...

Approach

Compute a per-conversation flag with NOT EXISTS rather than a LEFT JOIN plus COUNT(*), because a conversation with two handoffs would otherwise appear twice in the denominator. Aggregate by cust...


Submit Your Answer
Markdown supported

Related Questions