Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Merchants by City
00:00
5 left

Top Merchants by City

MediumSQL · PostgreSQL

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
Interviewer

Your question is Top Merchants by City. Start with the requirements and the three tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.