Skip to content
RED SAGSkills

Latest Status per Shipment

shipment_events is an append-only tracking log. For each shipment, find its most recent event: the one with the latest event_time. If two events of a shipment have the same event_time, the one with the larger event_id is the latest.

Return columns shipment_id, status, event_time. Row order does not matter.

Schema

CREATE TABLE shipment_events (
  event_id INTEGER PRIMARY KEY,
  shipment_id TEXT NOT NULL,
  status TEXT NOT NULL,
  event_time TEXT NOT NULL
);

Sample data

shipment_events

event_idshipment_idstatusevent_time
1SH-1001picked_up2026-05-01 08:00:00
2SH-1001in_transit2026-05-01 14:30:00
3SH-1002picked_up2026-05-01 09:10:00
4SH-1001out_for_delivery2026-05-02 07:45:00
5SH-1003picked_up2026-05-02 10:00:00
6SH-1002in_transit2026-05-02 11:20:00
7SH-1001delivered2026-05-02 12:05:00
Hint 1

Number the events of each shipment from newest to oldest and keep number 1.

Hint 2

event_id order is not the same as time order. A low id can still have the latest time.

Good practice for: Data Engineer, Backend Developer, Data Analyst

SQL (SQLite)

Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.