Chapter 9 · Interview Level
53. Detect Suspicious Large Withdrawal Patterns
Hard40 XPFinance
Flag accounts where a single withdrawal exceeds 1.5 times the account's average withdrawal amount. Return account_id, the suspicious transaction id (txn_id), the withdrawal amount, and the account's avg_withdrawal (rounded to 2 decimals). Use a CTE to compute average withdrawals per account, then join back. Order 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.