SQL QuestSQL Interview Questions › Joins

Chargeback Rate Per Merchant

MediumFreeQuerying BasicsJoinsAggregation & Grouping

Which merchants generate disputes? A chargeback rate is chargebacks ÷ transactions per merchant. Join merchants to transactions (INNER — a merchant with no transactions has no rate), then LEFT JOIN chargebacks on txn_id so merchants with zero disputes still count their transactions. Watch the grain: count chargebacks with COUNT(c.chargeback_id), which ignores the NULLs the LEFT JOIN produces; COUNT(*) would count every transaction as a dispute.

Return merchant_id, name, category, txn_count, chargeback_count, and chargeback_rate_pct (100.0 × chargebacks ÷ transactions, rounded to 2 decimals). Keep only merchants with at least 3 chargebacks (HAVING). Order by chargeback_rate_pct descending, then merchant_id ascending.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

merchants

merchant_idnamecategorycountryrisk_tier
1BigBox MartGroceryTRhigh
2Quick StopElectronicsJPhigh
3Aurora CafeTravelTRhigh

transactions

txn_idaccount_idamounttxn_atmerchant_idlatlngstatus
1149151.842026-03-04T12:39:39.078Z2440.342-74.4092completed
22110.722026-03-04T13:04:50.641Z752.936613.3229completed
335158.782026-03-04T13:27:15.528Z2552.739713.3134completed

chargebacks

chargeback_idtxn_idaccount_idmerchant_idreason_codeopened_atresolved_atstatusrelated_chargeback_id
1816010service_not_received2026-03-06T16:52:17.429Z2026-04-06T16:52:17.429ZsplitNULL
21644216fraud_card_not_present2026-03-16T23:50:46.792Z2026-04-22T23:50:46.792Zopen1
31724820fraud_card_present2026-03-12T05:22:57.195Z2026-04-14T05:22:57.195Zcardholder_won2

Expected output: PillPath 96 txns, 8 chargebacks, 8.33% ...

Hint

FROM merchants m JOIN transactions t ON t.merchant_id = m.merchant_id LEFT JOIN chargebacks c ON c.txn_id = t.txn_id GROUP BY m.merchant_id, m.name, m.category HAVING COUNT(c.chargeback_id) >= 3.

Concepts

SELECT JOIN LEFT JOIN GROUP BY HAVING ROUND GROUP BY + HAVING

Practise the topic: SQL practice questions · JOIN practice · GROUP BY exercises

In these company practice sets

Capital One · Stripe

A SQL Quest challenge matched to patterns reported for these companies — not a question any of them has published.

Related questions

Customers Who Never OrderedMedium · FreeAbove-Average Departments (Derived Table)Medium · FreeLEFT JOIN NULL Semantics: Inactive CustomersMedium · FreeManagement Hierarchy OverviewMedium · FreeCount Direct ReportsMedium · FreeCustomer Recency AnalysisMedium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test