Operational dashboards need a rolling window of recent activity — for example, showing orders from the past 30 days to help teams spot unusual spikes or drops in order volume. Unlike a fixed date range, this query always refers to "now" so the dashboard stays current without any code changes. 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.
Because this query uses CURRENT_DATE, the exact dates in the output depend on when you run it. The test cases use relative dates to verify the filtering logic independently of the current date.