Gaps longer than 45 days: 'Санкт-Петербург', premium
Instructions
A client's active day is a calendar day on which at least one transaction went through any of the client's accounts (by tx_time). A gap is an unbroken run of calendar days without transactions between two consecutive active days of a client (days before the client's first and after the last active day do not count). For clients from the city 'Санкт-Петербург' with segment 'premium', find all gaps strictly longer than 45 days. Output client_id, gap_start (the first day of the gap), gap_end (the last day of the gap) and gap_days (the number of days in the gap; if the active days are March 1 and March 5, the gap lasts 3 days: March 2 to March 4). Sort by gap_days descending, then client_id, then gap_start 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.