Premium problem46. Day-7 Retention by Signup Week

Medium Locked

users(user_id, signup_at) and sessions(user_id, session_at)

Group users into weekly cohorts by the Monday that starts their signup week. For each cohort return the size and the percentage of users who had at least one session on calendar day 7 after their signup date, exactly that day and no other.

Return signup_week, cohort_size and day7_retention_pct rounded to two decimals, ordered by signup_week. Every cohort appears, including ones where nobody came back.

Day 7 is a single day, not a window, so somebody returning on day 6 or day 8 does not count.

Tables

sessions

user_id  session_at
-------  -------------------
1        2026-06-10 09:00:00
2        2026-06-13 09:00:00
2        2026-06-15 09:00:00
3        2026-06-09 09:00:00

users

user_id  signup_at
-------  -------------------
1        2026-06-03 10:00:00
2        2026-06-07 10:00:00
3        2026-06-08 10:00:00

Expected result

signup_week  cohort_size  day7_retention_pct
-----------  -----------  ------------------
2026-06-01   2            50.00
2026-06-08   1            0.00

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query