← Gaps and islands, sessions

Returns after a pause over 10 days: BY/ios

Level: Middle100 XP

Instructions

A user's pause is the time between two consecutive events of the user (by event_time). For users from the country 'BY' with platform 'ios', find all returns after a pause strictly longer than 10 days (compare the exact interval, not the difference of dates). Output user_id, break_from (the time of the last event before the pause), break_to (the time of the first event after it) and pause_days (the length of the pause in days, rounded to 1 decimal place). Sort by the exact pause length descending (not by the rounded pause_days), then user_id, then break_to 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

events.user_id (0…N) ↔ users.id (1…1)purchases.user_id (0…N) ↔ users.id (1…1)eventsPKidintegerFKuser_idintegerpurchasesPKidintegerFKuser_idintegerusersPKidinteger
Exactly oneZero or oneZero or more
Table relationships
  • N:1Many-to-oneevents.user_id → users.id
  • N:1Many-to-onepurchases.user_id → users.id

Table data

PostgreSQL

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

Dataset schema