1843. Suspicious Bank Accounts

https://leetcode.com/problems/suspicious-bank-accounts

Description

Table: Accounts


+----------------+------+
| Column Name    | Type |
+----------------+------+
| account\_id     | int  |
| max\_income     | int  |
+----------------+------+
account\_id is the primary key for this table.
Each row contains information about the maximum monthly income for one bank account.

Table: Transactions


+----------------+----------+
| Column Name    | Type     |
+----------------+----------+
| transaction\_id | int      |
| account\_id     | int      |
| type           | ENUM     |
| amount         | int      |
| day            | datetime |
+----------------+----------+
transaction\_id is the primary key for this table.
Each row contains information about one transaction.
type is ENUM ('Creditor','Debtor') where 'Creditor' means the user deposited money into their account and 'Debtor' means the user withdrew money from their account.
amount is the amount of money depositied/withdrawn during the transaction.

Write an SQL query to report the IDs of all suspicious bank accounts.

A bank account is suspicious if the total income exceeds the max_income for this account for two or more consecutive months. The total income of an account in some month is the sum of all its deposits in that month (i.e., transactions of the type 'Creditor').

Return the result table in ascending order by transaction_id.

The query result format is in the following example:

ac

Last updated

Was this helpful?