← SQL and spreadsheet practice

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

  1. Join ticket_id AND episode. Only agent replies count, and only replies at or after opening. Timestamps are UTC.
  2. SLA is 30 elapsed minutes inclusive; this exercise has no business-hours pause. No eligible response means WAITING.
  3. 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 TEXTepisode INTEGERopened_at TEXT
Z112026-11-10 09:00:00
Z122026-11-11 10:00:00
Z212026-11-11 09:00:00
Z312026-11-11 08:00:00

replies

6 source rows · Download replies CSV

ticket_id TEXTepisode INTEGERsent_at TEXTactor TEXT
Z112026-11-10 09:20:00agent
Z122026-11-11 10:10:00customer
Z122026-11-11 11:05:00agent
Z122026-11-11 11:10:00agent
Z212026-11-11 09:30:00agent
Z312026-11-11 08:05:00bot

Plan the transformation

  1. Filter customer and bot messages before choosing MIN response timestamp.
  2. Group by the composite episode key so reopening starts a separate measurement.
  3. 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_idepisoderesponse_minutessla_status
Z1120MET
Z1265BREACHED
Z2130MET
Z31NULLWAITING

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

Try another case