← SQL workplace practice

Event sequence diagnostics · Original fictional data · Free files and full answers

Expose missing event sequence ranges

For consecutive stored sequence numbers per actor, report missing inclusive sequence ranges. A jump from 3 to 5 means missing 4, regardless of timestamps. Sort actor,missing_from.

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

  1. For consecutive stored sequence numbers per actor, report missing inclusive sequence ranges. A jump from 3 to 5 means missing 4, regardless of timestamps. Sort actor,missing_from.
  2. 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.
  3. 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, missing_from, missing_to. Sort order follows the task. Output has 2 rows; an empty CSV field means NULL.

Source data

events

16 source rows · Download events CSV

id INTEGERactor TEXTseq INTEGERminute INTEGERstate TEXTdelta INTEGER
1A10ok20
2A25fail-4
3A310fail-2
4A59ok10
5A670ok-5
6A775fail-3
7B10fail10
8B215ok-2
9B345fail-6
10B450fail-4
11B555fail2
12B6100ok6
13C120ok0
14C225ok-1
15C460fail5
16C562ok-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.

Download complete SQLite setup

A method you can reuse

  1. For consecutive stored sequence numbers per actor, report missing inclusive sequence ranges. A jump from 3 to 5 means missing 4, regardless of timestamps. Sort actor,missing_from.
  2. 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

Counting the size of a jump without its endpoints gives an incomplete replay request.

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(seq) OVER(PARTITION BY actor ORDER BY seq) p FROM events) SELECT actor,p+1 missing_from,seq-1 missing_to FROM x WHERE seq>p+1 ORDER BY actor,missing_from;
"actor","missing_from","missing_to"
"A","4","4"
"C","3","3"
Reference SQL · Complete expected CSV · Empty answer CSV

Choose another SQL task · Original data exception cases · Larger workplace projects