Consecutive salary months (3+): Kazan, threshold 20000
Instructions
A client's salary month is a calendar month in which the sum of their transactions of the category 'salary' (across all accounts, by tx_time) is at least 20000. For clients from the city 'Казань', find all runs of at least 3 salary months in a row (no missing months between them). Output client_id, first_month and last_month (the first days of the first and last month of the run, type date), months (the number of months in the run) and salary_total (the sum of the salary transactions over those months). Sort by months descending, then client_id, then first_month ascending.
Hints
Each next one is more detailed and costs more
Query
Result
Click Run to see the query result, or Check to submit your solution.
Dataset schema
Table relationships
- N:1Many-to-one
accounts.→client_id clients.id - N:1Many-to-one
transactions.→account_id accounts.id
Table data
Select a table in the diagram or list to view its rows.