Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Advanced SQL for Payment Metrics
00:00
5 left

Advanced SQL for Payment Metrics

HardSQL · PostgreSQL

Problem

Write a complex SQL query involving multiple joins, subqueries, and window functions to extract specific payment metrics at WePay.

Use the provided payment, merchant, refund, and dispute data. Include activity from January and February 2025.

Output

  1. One row per merchant and calendar month with payment activity
  2. Return merchant_name, country_code, payment_month, payment_count, successful_payment_count, gross_captured_amount, refund_amount, dispute_amount, net_amount, approval_rate, previous_month_gross_amount, and country_month_rank
  3. Order by country_code, payment_month, country_month_rank, and merchant_name

Schema

merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(100)Merchant display name
country_codeVARCHAR(2)Merchant country code
payments
ColumnTypeDescription
payment_idPKINTUnique payment identifier
merchant_idINTMerchant receiving the payment
payment_dateDATEDate the payment was created
statusVARCHAR(20)Payment processing status
amountDECIMAL(12,2)Payment amount
currencyVARCHAR(3)Payment currency
refunds
ColumnTypeDescription
refund_idPKINTUnique refund identifier
payment_idINTPayment being refunded
refund_amountDECIMAL(12,2)Refund amount
refund_dateDATEDate of refund
disputes
ColumnTypeDescription
dispute_idPKINTUnique dispute identifier
payment_idINTPayment under dispute
dispute_amountDECIMAL(12,2)Disputed amount
dispute_statusVARCHAR(20)Dispute resolution status
Tablesmerchantspaymentsrefundsdisputes
Interviewer

Your question is Advanced SQL for Payment Metrics. Start with the requirements and the four tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.