← Gaps and islands, sessions

Longest streak of active days: 'Казань', mass, Jun–Aug 2025

Level: Senior200 XP

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). For each client from the city 'Казань' with segment 'mass' who had at least one active day in the period June 1, 2025 to August 31, 2025 inclusive, find the longest streak of consecutive active days within this period (calendar days with no gaps; several transactions on one day count as one day): streak_days is its length in days, streak_start is its first day (if several streaks have the maximum length, the earliest one). Output client_id, streak_days, streak_start. Sort by streak_days descending, then client_id ascending.

Hints

Each next one is more detailed and costs more

Log in to open hints

Query

Result

Click Run to see the query result, or Check to submit your solution.

Dataset schema

accounts.client_id (0…N) ↔ clients.id (1…1)transactions.account_id (0…N) ↔ accounts.id (1…1)accountsPKidintegerFKclient_idintegerclientsPKidintegertransactionsPKidintegerFKaccount_idinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneaccounts.client_id → clients.id
  • N:1Many-to-onetransactions.account_id → accounts.id

Table data

PostgreSQL

Select a table in the diagram or list to view its rows.

Dataset schema