← Gaps and islands, sessions

Activity islands of client 42: Feb–Jul 2025

Level: Senior200 XP

Instructions

An island is a run of consecutive calendar days on each of which at least one transaction went through some account of the client with client_id = 42 (by tx_time). Consider only transactions in the period February 1, 2025 to July 31, 2025 inclusive. For each island, output island_start and island_end (its first and last day), island_days (the number of days in it) and pause_before (the number of days without transactions between the end of the previous island and the start of this one; NULL for the first island of the period). Sort by island_start 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