// advent-of-postgres/day-7
The Duplicate Events
The queue delivers some events twice. Find the latest status of every order before you add anything up.
The gift dashboard says the workshop shipped far more than the warehouse remembers. Shinny suspects the event queue: when a consumer times out, the queue delivers the same event again.
Every event is in order_events:
| Column | Type | Notes |
|---|---|---|
event_id |
bigint |
Primary key |
order_id |
int |
The order the event is about |
status |
text |
placed, packed, shipped or cancelled |
gift_value |
int |
The order's value, in candy canes |
received_at |
timestamptz |
When the event arrived |
An order's current status is the status of its most recent event. A duplicate has the same order and status as another event.
Your task
What is the total gift value of all orders whose current status is shipped?
Submit the number.
Stuck? Show a hint
DISTINCT ON keeps the first row of each group in the ORDER BY order, so order the newest event first.
Download today's data as SQL to solve it on your own Postgres (14 or later).
Solved this puzzle? Share it.
Tag @thedevopsdaily and share it with the community.
We earn commissions when you shop through the links below.
Bitrise
Managed runners for GitHub Actions
Bitrise Build Hub runs your GitHub Actions jobs on M4 Macs and AMD Linux machines. Change runs-on and keep your workflows, secrets and logs on GitHub.
Atomsized
AWS platform engineering and GitOps
Design and automation for reliable AWS and Kubernetes platforms, safer delivery workflows, and preview and UAT environments your engineers can understand and own.
DigitalOcean
Cloud infrastructure for developers
Simple, reliable cloud computing designed for developers
DevDojo
Developer community & tools
Join a community of developers sharing knowledge and tools
SMTPfast
Developer-first email API
Send transactional and marketing email through a clean REST API. Detailed logs, webhooks, and embeddable signup forms in one dashboard.
QuizAPI
Developer-first quiz platform
Build, generate, and embed quizzes with a powerful REST API. AI-powered question generation and live multiplayer.
Want to support DevOps Daily and reach thousands of developers?
Become a Sponsor