Chapter 6 · Subqueries
24. Transactions Above Account Type Average
Medium20 XPFinance
Find transactions whose amount exceeds the average transaction amount for their account's type. Join transactions to accounts to get the type, then use a correlated subquery comparing against the average for that type. Return transaction id, account_type, amount, and the type_avg. Sort by amount DESC. Limit to 30.
Tables
- PKidINT
- FKcustomer_id→ customers.idINT
- account_typeTEXT
- balanceREAL
- currencyTEXT
- opened_atTEXT
- statusTEXT
- 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.