Chapter 9 · Interview Level
48. Detect Suspicious Transaction Patterns
Hard40 XPFinance
The fraud team wants to find transactions whose amount is more than 1.5 times the average for their transaction type. Use a CTE to compute the average amount per type. Then join to flag above-average transactions. Return the transaction id, account_id, type, amount, and the type average (type_avg, rounded to 2 decimals). Sort by amount descending.
Tables
- PKidINT
- FKaccount_id→ accounts.idINT
- transaction_dateTEXT
- typeTEXT
- amountREAL
- balance_afterREAL
- descriptionTEXT
- reference_numberTEXT
Need help?
Ask Sol
AI tutor — looks at your current query and nudges you, without spoiling the answer.
Solution
Try the hints first — solving it yourself is what makes it stick.