← Practice

Sessions of BY/android users: pause over 120 minutes

Level: SeniorTopic: Gaps and islands, sessions200 XP

Instructions

A user's session is a run of the user's events (by event_time) in which the pause between consecutive events is at most 120 minutes; a pause strictly longer than 120 minutes starts a new session (a pause of exactly 120 minutes does not break a session). Do not use the session_id column. Session duration is the time from its first to its last event in minutes (0 for a single-event session). For each user from the country 'BY' with platform 'android' who has events, output user_id, sessions (the number of sessions), avg_events (the average number of events per session, rounded to 2 decimal places) and total_minutes (the total duration of the user's sessions in minutes, rounded to 1 decimal place). Sort by sessions descending, then user_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

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