Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.