Find accounts that have three or more consecutive deposit transactions (with no other transaction type in between, ordered by transaction id). Return the account_id and the count of such consecutive deposit streaks (streak_count). Use LAG or LEAD window functions to detect consecutive types. Order by streak_count descending, then account_id ascending.
Schema
🔑idINT
🔗account_idINT
transaction_dateTEXT
typeTEXT
amountREAL
balance_afterREAL
descriptionTEXT
reference_numberTEXT
postgresql
Run your query to see results
Press Ctrl + Enter to execute