temp) to calculate the total income per month for each account by summing up the amounts of 'Creditor' transactions grouped by account and month.temp CTE with the Accounts table to filter out the months where the income does not exceed the max_income.temp CTE to find pairs of rows with the same account_id and consecutive months (using PERIOD_DIFF).account_id and select the accounts that appear more than once, indicating at least two consecutive months of exceeding max_income.account_ids of the suspicious accounts.
erDiagram
Accounts {
int account_id
int max_income
}
Transactions {
int transaction_id
int account_id
enum type
int amount
datetime day
}
Accounts ||--o{ Transactions : has