Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Merchants by Transaction Volume

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

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

PayU needs a monthly view of its highest-volume merchants on the PayU payment platform. Write a PostgreSQL query that identifies the top three merchants by the number of successful transactions during January 2025.

Requirements

  1. Count only transactions with status = 'SUCCESS' during January 2025, using an inclusive start date and exclusive end date.
  2. Include merchants with no qualifying transactions, assigning them a volume of zero.
  3. Rank merchants by successful transaction volume in descending order, breaking ties with the lower merchant_id.
  4. Return only the top three ranked merchants, including their rank and transaction count.

Schema

merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(100)Merchant display name
business_categoryVARCHAR(50)Merchant business category
transactions
ColumnTypeDescription
transaction_idPKBIGINTUnique transaction identifier
merchant_idINTMerchant associated with the transaction
transaction_timestampTIMESTAMPTimestamp when the transaction was created
statusVARCHAR(20)Transaction processing status
payment_methodVARCHAR(30)Payment method used
Tablesmerchantstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results