Open lesson

Mission: the phantom third passage

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

Brief

Define a report's grain and select one version per event without erasing history or inflating counts.

Voss holds up a report claiming three passages on the accident night. Mara gives you three copied rows: R1-v1 (North, 08:00), R1-v2 (South, 09:00), and R2-v1 (West, 08:30). Those times are when corrections were recorded the next day, not the driving times. Imani needs a clear count before questioning the vehicle registry. The scene's deadline is fictional; there is no exercise timer.

Your mission

  1. State the report's grain if the question is “how many road events?”
  2. Name the business key and version key on R1-v2.
  3. Identify the two rows selected by ROW_NUMBER and explain the tie rule.
  4. Say what the total 2 proves and what it cannot yet prove.

How to check your work

  • The grain is one event_id per row.
  • event_id is R1 and revision_id is R1-v2.
  • R1-v2 and R2-v1 are selected by a defined revision order.
  • Two events are represented, without proving a vehicle's physical identity.

Course example

CREATE TABLE event_revisions (
    revision_id TEXT PRIMARY KEY,
    event_id TEXT NOT NULL,
    revision_at TEXT NOT NULL,
    vehicle_tag TEXT NOT NULL,
    reported_gate TEXT NOT NULL
);
INSERT INTO event_revisions VALUES
    ('R1-v1', 'R1', '2026-04-13T08:00:00Z', 'NOCTIS-01', 'North'),
    ('R1-v2', 'R1', '2026-04-13T09:00:00Z', 'NOCTIS-01', 'South'),
    ('R2-v1', 'R2', '2026-04-13T08:30:00Z', 'TEST-02', 'West');

WITH ranked AS (
    SELECT event_id, revision_id, vehicle_tag, reported_gate,
           ROW_NUMBER() OVER (
               PARTITION BY event_id
               ORDER BY revision_at DESC, revision_id DESC
           ) AS position
    FROM event_revisions
)
SELECT event_id, revision_id, vehicle_tag, reported_gate
FROM ranked
WHERE position = 1
ORDER BY event_id;

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with -- are task reminders. SQL ignores them. Write your query beneath them.

SQL console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.sql

Current editor source. Inspection shows your current edits.

-- State the report's grain if the question is “how many road events?”
-- Name the business key and version key on R1-v2.
-- Identify the two rows selected by ROW_NUMBER and explain the tie rule.
-- Say what the total 2 proves and what it cannot yet prove.

exemple.sql

Declarative lesson asset; this is not a file created in the Python filesystem.

CREATE TABLE event_revisions (
    revision_id TEXT PRIMARY KEY,
    event_id TEXT NOT NULL,
    revision_at TEXT NOT NULL,
    vehicle_tag TEXT NOT NULL,
    reported_gate TEXT NOT NULL
);
INSERT INTO event_revisions VALUES
    ('R1-v1', 'R1', '2026-04-13T08:00:00Z', 'NOCTIS-01', 'North'),
    ('R1-v2', 'R1', '2026-04-13T09:00:00Z', 'NOCTIS-01', 'South'),
    ('R2-v1', 'R2', '2026-04-13T08:30:00Z', 'TEST-02', 'West');

WITH ranked AS (
    SELECT event_id, revision_id, vehicle_tag, reported_gate,
           ROW_NUMBER() OVER (
               PARTITION BY event_id
               ORDER BY revision_at DESC, revision_id DESC
           ) AS position
    FROM event_revisions
)
SELECT event_id, revision_id, vehicle_tag, reported_gate
FROM ranked
WHERE position = 1
ORDER BY event_id;