Streaks of active weeks: 'Екатеринбург', vip, groceries
Instructions
A week is 7 days from Monday to Sunday (as in date_trunc('week', …)); a week is active for a client if at least one transaction of the category 'groceries' went through in it on any of the client's accounts. A streak is a maximal run of consecutive active weeks with no missing weeks (it may consist of a single week). For each client from the city 'Екатеринбург' with segment 'vip' who has at least one active week, output client_id, active_weeks (the number of active weeks), streaks (the number of streaks) and longest_streak (the length of the longest streak in weeks). Sort by longest_streak descending, then active_weeks descending, then client_id 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.