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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Monthly Merchant Volume Ranking with Window Functions
00:00
5 left

Monthly Merchant Volume Ranking with Window Functions

HardSQL · PostgreSQL

Problem

Write an advanced SQL query to aggregate transaction volumes, handle window functions, and efficiently stage data transformations.

Use the provided Brex card, merchant, and transaction tables. Include only settled USD transactions during Q1 2025.

Output

  1. One row per merchant and transaction month with transaction_month, merchant_id, merchant_name, transaction_count, total_volume, and merchant_rank.
  2. Rank merchants within each month by descending total volume, with ties sharing a rank.
  3. Sort by transaction_month, merchant_rank, and merchant_id.

Schema

merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(100)Merchant display name
merchant_categoryVARCHAR(50)Merchant business category
cards
ColumnTypeDescription
card_idPKVARCHAR(20)Unique Brex card identifier
merchant_idINTMerchant associated with the card
card_statusVARCHAR(20)Current card status
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
card_idVARCHAR(20)Card used for the transaction
transaction_dateDATETransaction posting date
amountNUMERIC(12,2)Transaction amount in the transaction currency
currencyVARCHAR(3)ISO currency code
statusVARCHAR(20)Transaction processing status
Tablestransactionscardsmerchants
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.