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
Rank Drivers of Failed Payments
00:00
5 left

Rank Drivers of Failed Payments

MediumSQL · PostgreSQL

Problem

FinFlow wants to understand which account and transaction attributes are most associated with failed payments in June 2024.

Write a SQL query to return the top-ranked value for each of these dimensions: country_code, payment_method, risk_tier, and surface_name.

Requirements

  1. Use only transactions from 2024-06-01 through 2024-06-30.
  2. For each dimension value, calculate:
    • total_transactions
    • failed_transactions where status = 'failed'
    • failure_rate = failed_transactions / total_transactions, rounded to 4 decimals
  3. Treat missing dimension values as 'Unknown'.
  4. Only keep dimension values with at least 2 failed transactions.
  5. Rank values within each dimension by:
    1. failed_transactions descending
    2. total_transactions descending
    3. driver_value ascending
  6. Return only rows with failure_rank = 1.

Schema

transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
account_idINTAccount associated with the transaction
transaction_tsTIMESTAMPTimestamp when the transaction was attempted
payment_methodVARCHAR(50)Payment method used for the transaction
statusVARCHAR(20)Final transaction status
failure_reasonVARCHAR(100)Failure reason when a transaction fails
amountNUMERIC(10,2)Transaction amount
accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
country_codeVARCHAR(2)Country code for the account
risk_tierVARCHAR(20)Risk segment assigned to the account
merchant_idINTMerchant linked to the account
merchants
ColumnTypeDescription
merchant_idPKINTUnique merchant identifier
surface_nameVARCHAR(50)Product surface where the merchant operates
merchant_nameVARCHAR(100)Merchant display name
Tablestransactionsaccountsmerchants
Interviewer

Your question is Rank Drivers of Failed Payments. Start with the requirements and the three 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.