Your question is Top Merchants by City. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
DoorDash wants a city-level view of the merchants generating the most revenue. Write a PostgreSQL query using data through 2026-08-29 to find the top three merchants by delivered order revenue in each city during the previous 30 days, from 2026-07-31 through 2026-08-29 inclusive.
status = 'delivered' and order_total values from the 30-day period.merchant_id, and return ranks 1 through 3.| Column | Type | Description |
|---|---|---|
| city_idPK | INT | Unique city identifier |
| city_name | VARCHAR(100) | DoorDash market name |
| Column | Type | Description |
|---|---|---|
| merchant_idPK | INT | Unique merchant identifier |
| merchant_name | VARCHAR(150) | Merchant display name |
| city_id | INT | City where the merchant operates |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| merchant_id | INT | Merchant associated with the order |
| order_total | NUMERIC(10,2) | Revenue attributed to the order |
| placed_at | TIMESTAMP | Timestamp when the order was placed |
| status | VARCHAR(20) | Order lifecycle status |