Arriving Wednesday
- O(n²) · Very hard
- Full plan
- SQL
- dates
- conditionals
Problem
The store delivers in three business days: the count starts the day after the order is placed, and neither Saturday nor Sunday counts. Something ordered on a Monday arrives on Thursday; something ordered on a Saturday arrives on Wednesday.
The '%w' format of STRFTIME gives the day of the week as text from '0' to '6', and '0' is Sunday.
Show three columns: each order's number, its date, and the day it gets delivered. The earliest deliveries go on top and, when the day is the same, the lower order number goes first.
Orders dated up to today, January 15, 2026, are included. The one dated the 20th stays out: with a mistyped date, there's no day to promise.
What it has to return
These rows, in this order
| id | placed | arrives |
|---|---|---|
| 1 | 2026-01-03 | 2026-01-07 |
| 2 | 2026-01-04 | 2026-01-07 |
| 3 | 2026-01-04 | 2026-01-07 |
| 4 | 2026-01-09 | 2026-01-14 |
| 5 | 2026-01-10 | 2026-01-14 |
| 6 | 2026-01-11 | 2026-01-14 |
| 7 | 2026-01-12 | 2026-01-15 |
| 8 | 2026-01-12 | 2026-01-15 |
| 9 | 2026-01-14 | 2026-01-19 |
| 10 | 2026-01-15 | 2026-01-20 |
| 11 | 2026-01-15 | 2026-01-20 |
This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.
You start with this
SQL
SELECT id, placed,
DATE(placed, '+3 days') AS arrives
FROM orders
ORDER BY arrives, id;It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.
More O(n²) challenges
- Best day yetSQL · window functions · grouping · subqueries
- First with lastSQL · window functions · joins · grouping
- How soon they're backSQL · window functions · dates · grouping
- January off the shelfSQL · dates · nulls · grouping
- Lighthouse, TheSQL · strings · conditionals · sorting
- One raise, not twoSQL · changing data · conditionals