DoorDash's operations team runs a daily operations check - write a rolling query that captures recent order activity without hardcoding dates that go stale. Using the orders table, return id, customer_id, amount, and created_at for every order placed within the last 30 days, ordered by created_at descending (most recent first).
orders
| column | type |
|---|---|
| id | INTEGER |
| customer_id | INTEGER |
| amount | NUMERIC |
| created_at | DATE |
The seed uses CURRENT_DATE - N to keep data relevant regardless of when you run it. Conceptually, if today is 2026-04-20:
| id | customer_id | amount | created_at |
|---|---|---|---|
| 1 | 1 | 99.99 | 2026-04-15 (–5) |
| 2 | 2 | 49.50 | 2026-04-05 (–15) |
| 3 | 1 | 200.00 | 2026-03-22 (–29) |
| 4 | 3 | 75.00 | 2026-03-20 (–31) |
| 5 | 2 | 150.00 | 2026-02-19 (–60) |
| id | customer_id | amount | created_at |
|---|---|---|---|
| 1 | 1 | 99.99 | 2026-04-15 |
| 2 | 2 | 49.50 | 2026-04-05 |
| 3 | 1 | 200.00 | 2026-03-22 |
Orders 4 and 5 are 31 and 60 days old respectively, so they fall outside the 30-day window. The three qualifying rows are returned most-recent-first.