← Practice

Day-1 retention by week: 4 weeks from January 6, 2025

Level: MiddleTopic: Retention, funnels, cohorts100 XP

Instructions

A cohort is the users who signed up (users.signup_at) in one calendar week; a week starts on Monday, and cohort_week is the date of that Monday (date_trunc('week', signup_at)::date). Take the users who signed up from January 6, 2025 to February 2, 2025 inclusive. A user is retained on day 1 if they have at least one event (events) on exactly the 1st calendar day after signup: event_time::date = signup_at::date + 1 (the signup day is day 0). For each cohort, output cohort_week, cohort_size (the number of users in the cohort, including those with no events at all), retained (the number of retained users; each is counted once) and retention_pct (retained / cohort_size × 100, rounded to 1 decimal place). Sort by cohort_week.

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