SQL support operations · Original fictional case · Free files and answers
Measure first response after a ticket reopens
A support lead needs one first-response measurement per opening episode. A response from an earlier episode cannot satisfy the SLA for a reopened ticket.
Suggested time: 15–25 minutes. All records, companies, rates and work policies are invented for this exercise.
Your output contract
- Join ticket_id AND episode. Only agent replies count, and only replies at or after opening. Timestamps are UTC.
- SLA is 30 elapsed minutes inclusive; this exercise has no business-hours pause. No eligible response means WAITING.
- Return ticket_id,episode,response_minutes,sla_status. Round SQLite elapsed minutes to the nearest integer for these exact-minute examples.
Required columns: ticket_id, episode, response_minutes, sla_status. Row order is part of the contract. Empty output CSV fields represent NULL; zero remains 0.
Original source tables
episodes
4 source rows · Download episodes CSV
| ticket_id TEXT | episode INTEGER | opened_at TEXT |
|---|---|---|
| Z1 | 1 | 2026-11-10 09:00:00 |
| Z1 | 2 | 2026-11-11 10:00:00 |
| Z2 | 1 | 2026-11-11 09:00:00 |
| Z3 | 1 | 2026-11-11 08:00:00 |
replies
6 source rows · Download replies CSV
| ticket_id TEXT | episode INTEGER | sent_at TEXT | actor TEXT |
|---|---|---|---|
| Z1 | 1 | 2026-11-10 09:20:00 | agent |
| Z1 | 2 | 2026-11-11 10:10:00 | customer |
| Z1 | 2 | 2026-11-11 11:05:00 | agent |
| Z1 | 2 | 2026-11-11 11:10:00 | agent |
| Z2 | 1 | 2026-11-11 09:30:00 | agent |
| Z3 | 1 | 2026-11-11 08:05:00 | bot |
Plan the transformation
- Filter customer and bot messages before choosing MIN response timestamp.
- Group by the composite episode key so reopening starts a separate measurement.
- Use a LEFT JOIN for unanswered Z3 and keep its duration NULL.
Watch for this mistake
MIN reply per ticket would reuse Z1’s response from the previous day and conceal the reopened episode breach.
Run and check your SQLite result
The database runs locally in a worker. Use one SELECT or WITH query. Your query is saved on this device when storage is available. Download your SQL before clearing browser data.
Or work in Excel or another spreadsheet, then upload the final CSV with exactly the required columns.
Worked SQL and complete expected output
Two episodes meet SLA, one breaches, and one is waiting. Waiting is reported separately from completed response times.
WITH r AS (SELECT e.ticket_id,e.episode,e.opened_at,MIN(p.sent_at) first_reply FROM episodes e LEFT JOIN replies p ON e.ticket_id=p.ticket_id AND e.episode=p.episode AND p.actor='agent' AND p.sent_at>=e.opened_at GROUP BY e.ticket_id,e.episode,e.opened_at), d AS (SELECT *,CAST(ROUND((julianday(first_reply)-julianday(opened_at))*1440) AS INTEGER) response_minutes FROM r) SELECT ticket_id,episode,response_minutes,CASE WHEN first_reply IS NULL THEN 'WAITING' WHEN response_minutes<=30 THEN 'MET' ELSE 'BREACHED' END sla_status FROM d ORDER BY ticket_id,episode;
| ticket_id | episode | response_minutes | sla_status |
|---|---|---|---|
| Z1 | 1 | 20 | MET |
| Z1 | 2 | 65 | BREACHED |
| Z2 | 1 | 30 | MET |
| Z3 | 1 | NULL | WAITING |
Download reference SQL · Download complete expected CSV · Download an empty answer CSV · Download SQLite setup
What to pass to a colleague
Keep the checked output and SQL or spreadsheet result. Explain the exception policy, the cross-check above and any held records. The checker confirms this fixed case’s output; it does not evaluate arbitrary private business data.
SQLite SELECT, joins and aggregation reference · Continue with the larger workplace projects