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