SQL QuestSQL Interview Questions › Joins

Velocity Rule — 5+ Transactions in 5 Minutes

HardProQuerying BasicsJoinsAggregation & GroupingDate Functions

Velocity = the most reliable fraud signal. A legitimate user makes ~5 transactions per day. A compromised card hits 10+ transactions in 5 minutes as the fraudster tests stolen credentials. Find every transaction where the same account had 5 or more transactions in the 5 minutes leading up to it (inclusive of the current row).

Show account_id, txn_id, txn_at, amount, txns_last_5_min. Order by account_id, txn_at.

SQLite doesn't support RANGE BETWEEN INTERVAL in window functions — use a self-join + GROUP BY instead. The trick: count rows where t2.txn_at is within (t1.txn_at - 5 min) and t1.txn_at.

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

Expected output: Velocity-burst transactions

Hint

This is a Pro challenge — the hint, the step-by-step tutor and the reference solution open in the app.

Concepts

SELECT JOIN GROUP BY Date Functions Self-Join

Practise the topic: SQL practice questions · JOIN practice · GROUP BY exercises · Date function practice · Advanced SQL interview questions

Related questions

Multi-CTE Revenue PipelineHard · FreeEmployees Earning More Than ManagerHard · ProEmployees with Similar SalariesHard · ProMoving Average with Dynamic WindowHard · ProDetect Repeat Buyers Within 7 DaysHard · ProRecursive Team Size RollupHard · Pro

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