Compute the median delivery time per dark store WITHOUT using a MEDIAN or PERCENTILE function. Delivery minutes = (delivered_at - placed_at) in minutes (can be fractional). Orders with delivered_at NULL are not delivered and are excluded; stores with no delivered order are not shown. For an even count the median is the average of the two middle values. Return store_id, delivered_orders and median_minutes (ROUND to 1). Order by median_minutes DESC, then store_id.
| Column | Type |
|---|---|
| order_id | INTEGER |
| store_id | TEXT |
| placed_at | TIMESTAMP |
| delivered_at | TIMESTAMP |
| order_id | store_id | placed_at | delivered_at |
|---|---|---|---|
| 1 | S1 | 2026-07-01 10:00:00 | 2026-07-01 10:08:00 |
| 2 | S1 | 2026-07-01 11:00:00 | 2026-07-01 11:12:00 |
| 3 | S1 | 2026-07-01 12:00:00 | 2026-07-01 12:10:00 |
| 4 | S2 | 2026-07-01 10:00:00 | 2026-07-01 10:15:00 |
| 5 | S2 | 2026-07-01 10:30:00 | 2026-07-01 10:39:00 |
| 6 | S2 | 2026-07-01 11:00:00 | 2026-07-01 11:11:00 |
| 7 | S2 | 2026-07-01 12:00:00 | 2026-07-01 12:20:00 |
| 8 | S3 | 2026-07-01 09:00:00 | 2026-07-01 09:07:00 |
| store_id | delivered_orders | median_minutes |
|---|---|---|
| S2 | 4 | 13 |
| S1 | 3 | 10 |
| S3 | 1 | 7 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ Merge Overlapping Driver Online Sessions · Reporting Chain to the Top ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.