Event sequence diagnostics · Original fictional data · Free files and full answers
Measure recovery from the start of each failure run
A failure run is consecutive fail events in seq order. Return actor,first_fail_seq,recovery_seq,elapsed_minutes for each run that ends in ok. Time is recovery minute minus first-fail minute, even if negative. Sort actor,first_fail_seq.
Use this fixed business case to build a checked CSV and a replayable SQL handoff. No account required. Scenario datasets are shared across related exercises; each exercise has its own decision and output contract.
Your output contract
- A failure run is consecutive fail events in seq order. Return actor,first_fail_seq,recovery_seq,elapsed_minutes for each run that ends in ok. Time is recovery minute minus first-fail minute, even if negative. Sort actor,first_fail_seq.
- Return exactly the declared columns and order. Money uses integer cents; all time values are elapsed UTC minutes unless a field is explicitly a day index. NULL is unknown and differs from numeric zero.
- These are original fictional records and exercise policies. All source tables in this case are included in the downloadable pack.
Return columns exactly as actor, first_fail_seq, recovery_seq, elapsed_minutes. Sort order follows the task. Output has 4 rows; an empty CSV field means NULL.
Source data
events
16 source rows · Download events CSV
| id INTEGER | actor TEXT | seq INTEGER | minute INTEGER | state TEXT | delta INTEGER |
|---|---|---|---|---|---|
| 1 | A | 1 | 0 | ok | 20 |
| 2 | A | 2 | 5 | fail | -4 |
| 3 | A | 3 | 10 | fail | -2 |
| 4 | A | 5 | 9 | ok | 10 |
| 5 | A | 6 | 70 | ok | -5 |
| 6 | A | 7 | 75 | fail | -3 |
| 7 | B | 1 | 0 | fail | 10 |
| 8 | B | 2 | 15 | ok | -2 |
| 9 | B | 3 | 45 | fail | -6 |
| 10 | B | 4 | 50 | fail | -4 |
| 11 | B | 5 | 55 | fail | 2 |
| 12 | B | 6 | 100 | ok | 6 |
| 13 | C | 1 | 20 | ok | 0 |
| 14 | C | 2 | 25 | ok | -1 |
| 15 | C | 4 | 60 | fail | 5 |
| 16 | C | 5 | 62 | ok | -2 |
Field dictionary and schema
events: id INTEGER — Stable record or business key; retain its declared type. actor TEXT — Literal text label or key; comparisons use SQLite binary text semantics. seq INTEGER — Exact integer measurement; use the task rule for units and ordering. minute INTEGER — Exact integer measurement; use the task rule for units and ordering. state TEXT — Literal text label or key; comparisons use SQLite binary text semantics. delta INTEGER — Exact integer measurement; use the task rule for units and ordering.
A method you can reuse
- A failure run is consecutive fail events in seq order. Return actor,first_fail_seq,recovery_seq,elapsed_minutes for each run that ends in ok. Time is recovery minute minus first-fail minute, even if negative. Sort actor,first_fail_seq.
- Inspect the source grain, keys and ties before writing the query. Use the worked SQL and complete expected CSV to review any mismatch.
Watch for this wrong turn
Using the last failure as the start understates the time spent in failure.
Run and check in SQLite
Your SQL runs locally in the existing SQLite worker. The checker compares every column, row, type, value and row order with this fixed output. It accepts equivalent SELECT or WITH queries. Browser storage keeps your SQL on this device when available.
Complete worked SQL and expected output
WITH x AS (SELECT *,LAG(state) OVER(PARTITION BY actor ORDER BY seq) p FROM events), f AS (SELECT * FROM x WHERE state='fail' AND (p IS NULL OR p<>'fail')) SELECT f.actor,f.seq first_fail_seq,(SELECT MIN(e.seq) FROM events e WHERE e.actor=f.actor AND e.seq>f.seq AND e.state='ok') recovery_seq,(SELECT e.minute FROM events e WHERE e.actor=f.actor AND e.seq=(SELECT MIN(z.seq) FROM events z WHERE z.actor=f.actor AND z.seq>f.seq AND z.state='ok'))-f.minute elapsed_minutes FROM f WHERE EXISTS(SELECT 1 FROM events e WHERE e.actor=f.actor AND e.seq>f.seq AND e.state='ok') ORDER BY actor,first_fail_seq;
"actor","first_fail_seq","recovery_seq","elapsed_minutes" "A","2","5","4" "B","1","2","15" "B","3","6","55" "C","4","5","2"Reference SQL · Complete expected CSV · Empty answer CSV
Choose another SQL task · Original data exception cases · Larger workplace projects