Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merchant Volume Trends

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

Your question is Merchant Volume Trends. 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

Mastercard analytics teams monitor transaction activity by Merchant Category Code, or MCC. Treat transaction volume as the number of settled transactions. Write a PostgreSQL query that summarizes daily activity for each matched merchant category.

Requirements

  1. Join settled transactions to merchant_categories using mcc_code.
  2. Return the daily transaction count for each category and date.
  3. Calculate a cumulative running total within each category, ordered by transaction date.
  4. Calculate a three-row moving average of daily transaction volume, including the current day and up to the two preceding category rows. Round it to two decimal places.

Schema

payment_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
mcc_codeINTMastercard Merchant Category Code
transaction_dateDATESettlement date
statusVARCHAR(20)Transaction processing status
merchant_categories
ColumnTypeDescription
mcc_codePKINTMastercard Merchant Category Code
category_nameVARCHAR(100)Human-readable merchant category
Tablespayment_transactionsmerchant_categories
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results