Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Merchants by Category

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

Your question is Top Merchants by Category. 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

Write a query to identify the top 3 merchants by transaction volume for each category in the last 30 days for Phonepe.

Use successful transactions only. The 30-day period includes today and the preceding 30 calendar days.

Output

  1. One row per qualifying merchant, with category_name, merchant_id, merchant_name, and transaction_volume.
  2. Return at most three merchants per category, ordered by category name, transaction volume descending, and merchant ID ascending for ties.
  3. Transactions with a NULL transaction_date or NULL status are ignored.

Schema

categories
ColumnTypeDescription
category_idPKINTUnique category identifier
category_nameVARCHAR(100)PhonePe merchant category name
merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(150)Merchant display name
category_idINTCategory assigned to the merchant
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
merchant_idINTMerchant associated with the transaction
transaction_dateDATECalendar date of the transaction
statusVARCHAR(40)Transaction processing status
Tablestransactionsmerchantscategories
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results