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
- 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.
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;