Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Payment Performance

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

Your question is SQL for Payment Performance. Start with the requirements and the three 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

Write a SQL query to analyze payment operations performance by merchant and region, including success rate, failure rate, and month-over-month trends at Adyen.

Use payment operations from January through April 2024. Include only successful and failed operations, and compare each merchant-region combination across every month in that period.

Output

  1. One row per merchant, region, and calendar month, including months with no qualifying operations.
  2. Columns: merchant_id, merchant_name, region_code, month, operation_count, success_rate, failure_rate, success_rate_mom_pp, and failure_rate_mom_pp.
  3. Rates are percentages rounded to two decimals. Month-over-month values are percentage-point changes from the prior calendar month and are null when either rate is unavailable.
  4. Sort by merchant_id, region_code, and month ascending.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique Adyen operating region identifier
region_codeVARCHAR(10)Short region or country code
region_nameVARCHAR(100)Display name of the operating region
merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
merchant_nameVARCHAR(120)Merchant display name
region_idINTMerchant's configured operating region
activeBOOLEANWhether the merchant is currently active
payment_operations
ColumnTypeDescription
operation_idPKINTUnique payment operation identifier
merchant_idINTMerchant associated with the operation
region_idINTRegion where the operation was processed
processed_atTIMESTAMPTimestamp when the operation was processed
statusVARCHAR(20)Payment outcome, such as success, failed, or pending
amountNUMERIC(12,2)Payment amount in the processing currency
Tablesmerchantsregionspayment_operations
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results