SQL QuestSQL Interview Questions › Joins

Transaction Share by Merchant Category

EasyFreeQuerying BasicsJoinsAggregation & GroupingSubqueries & CTEs

Where does the card get used? Category lives on the merchants table, not on the transaction, so join on merchant_id first. Then count transactions per category and express each count as a share of ALL transactions — a scalar subquery (SELECT COUNT(*) FROM transactions) in the denominator does it in one pass.

Return category, txn_count, and share_pct (100.0 × count ÷ total transactions, rounded to 2 decimals). Order by txn_count descending, then category ascending. Multiply by 100.0, not 100 — integer division would round every share to 0.

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

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

merchants

merchant_idnamecategorycountryrisk_tier
1BigBox MartGroceryTRhigh
2Quick StopElectronicsJPhigh
3Aurora CafeTravelTRhigh

Expected output: Clothing 447 20.65, Travel 373 17.23 ...

Hint

The hint for this one spells out most of the query, so it stays in the editor. Reach for SELECT, JOIN, GROUP BY, and open the hint there if you stall.

Concepts

SELECT JOIN GROUP BY Subquery ROUND JOIN + GROUP BY

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

In these company practice sets

Capital One · Plaid

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

Related questions

Your First JOINEasy · FreeJOIN with a FilterEasy · FreeLEFT JOIN: Watch the NULLs AppearEasy · FreeCounting Across a JOINEasy · FreeSignup-Month Cohort SpendEasy · FreeCard Spend by CountryEasy · 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