Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Merchants With Ranking

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

Your question is Top Merchants With Ranking. Start with the requirements and the two 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 Marketplace analytics needs a ranked view of high-performing merchants for January 2025. Write an efficient PostgreSQL query that filters valid transactions, aggregates merchant performance, and ranks qualifying merchants within each cuisine.

Requirements

  1. Include only active merchants and completed transactions from January 1 through January 31, 2025, with a positive transaction amount.
  2. Require at least two qualifying transactions and at least $90 in total revenue.
  3. Use a window function to rank merchants by total revenue within each cuisine, returning the top two per cuisine.
  4. Return merchant_name, cuisine, qualifying_transactions, total_revenue, and cuisine_rank, ordered by cuisine and rank.

Schema

merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(100)DoorDash merchant name
cuisineVARCHAR(50)Cuisine category
is_activeBOOLEANWhether the merchant is active
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
merchant_idINTMerchant associated with the transaction
transaction_dateDATEDate the transaction occurred
statusVARCHAR(20)Transaction processing status
amountNUMERIC(10,2)Transaction amount in dollars
Tablesmerchantstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results