Streaks of four or more days of opening the app
The task
The engagement team wants to find habit-forming users. A user has an app-open day when they fire at least one app_open event on that UTC calendar day. A streak is a run of consecutive app-open days with no day missing in between. A user can have several streaks, and one day with several app_open events is still one day.
Return every streak that lasts 4 days or more:
user_idstreak_start: the first day of the streak (a date)streak_end: the last day of the streak (a date)streak_days: how many days the streak lasts
A streak is reported in full: if a user opens the app on 5 days in a row, the answer has one row with streak_days 5, not two rows. Sort by user_id, then streak_start.
Expected output
user_idstreak_startstreak_endstreak_days- Sorted by user_id ascending, then streak_start ascending.
- Checked on the sample and on 2 hidden datasets. How grading works
Tables Mobile shopping app · click a name to insert it
users360 rows in the sample
One row per user. Key: user_id.
| int | Unique id. | |
| timestamp | Sign-up time (UTC). | |
| text | Two-letter country code. | |
| text | ios, android or web. | |
| text | organic, paid, referral or partner. NULL when unknown. |
events7,616 rows in the sample
One row per tracked event. Key: event_id.
| bigint | Unique id. | |
| int | Who fired it. | |
| text | app_open, search, view_item, add_to_cart, begin_checkout, purchase or share. | |
| timestamp | When (UTC). | |
| text | Session the event belongs to. NULL for a few events sent from the background. | |
| numeric(10,2) | Order value for purchase events, NULL otherwise. |
experiment_assignments349 rows in the sample
Which variant each user saw in each experiment. Key: user_id, experiment.
| int | The user. | |
| text | new_onboarding or one_tap_checkout. | |
| text | control or treatment. | |
| timestamp | When the user was assigned (UTC). |
Related questions
Loading the editor and PostgreSQL
Loading the editor and PostgreSQL