Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Merchants by City

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Requirements

  1. Join merchants to their cities and orders.
  2. Include only orders with status = 'delivered' and order_total values from the 30-day period.
  3. Aggregate revenue by city and merchant.
  4. Rank merchants independently within each city, breaking revenue ties by the smaller merchant_id, and return ranks 1 through 3.

Schema

cities
ColumnTypeDescription
city_idPKINTUnique city identifier
city_nameVARCHAR(100)DoorDash market name
merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(150)Merchant display name
city_idINTCity where the merchant operates
orders
ColumnTypeDescription
order_idPKINTUnique order identifier
merchant_idINTMerchant associated with the order
order_totalNUMERIC(10,2)Revenue attributed to the order
placed_atTIMESTAMPTimestamp when the order was placed
statusVARCHAR(20)Order lifecycle status
Tablescitiesmerchantsorders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results