Describe the SQL and data model for weekly cohort retention

Anchoring activity to signup cohort.
Join users and activity, compute week offset per user, group by cohort and offset for retention.
Counting active users globally without cohort anchoring.
What's really being asked
This question tests whether you can model time-bound user behavior relationally and avoid the classic trap of aggregate retention. The interviewer cares that you understand a user belongs to exactly one signup cohort, and that every later activity must be measured relative to that specific origin point. They also want to see that you know how to handle calendar weeks, distinct user counting, and denominator management in SQL.
The full answer
A strong answer describes two core tables. First, a users table with at least user_id and signup_date or signup_week. Second, an activity table with user_id and activity_date. The query should join users to activity on user_id, then compute a week difference using a formula like datediff week or truncating both dates to week start. The result is grouped by signup_week and week_offset, counting distinct user_ids in the numerator. The denominator is the total distinct users in each signup_week cohort. Finally, the answer should mention pivoting the result either with conditional aggregation like sum case when week_offset equals one then one end or with a crosstab presentation so that columns represent week two, week three, and week four retention.
The mistakes people make
The biggest red flag is computing global active users per week and calling that retention. Another error is using calendar weeks for both signup and activity without normalizing to a common week start, which creates boundary mismatches. Some candidates forget to count distinct users and instead count activity rows, inflating retention when power users return many times. A subtle mistake is including users who signed up mid-week in a weekly cohort without deciding whether to use strict seven-day rolling windows or calendar weeks, because the two definitions produce different percentages.
What usually comes next
The interviewer may ask how you would handle missing weeks where a user returns after a gap, and whether you count that as retained in the skipped weeks. They might ask how to adapt the query for daily or monthly granularity, or how to add an experiment dimension so you can compare retention between test and control groups. Another common extension is asking how you would optimize the query when the activity table has billions of rows, which leads to partitioning and indexing strategies.
A concrete example
Imagine a users table where user one signs up on January first and user two signs up on January eighth. The activity table shows user one active on January first, eighth, and fifteenth, while user two is active only on January eighth. Using calendar weeks, both users belong to distinct signup cohorts. The week zero retention for the January first cohort is one hundred percent because user one was active that week. The week one retention is also one hundred percent because user one returned the week of January eighth. The January eighth cohort has one hundred percent week zero retention but zero percent week one retention if user two does not return. The SQL would express this by truncating dates to week, joining, and grouping.
Interview question
When calculating weekly cohort retention, why is computing week_offset from each user's signup_date preferable to grouping activity by calendar week?
- a.It reduces query cost by avoiding joins between users and activity tables
- b.It eliminates the need to count distinct user_ids in the numerator
- c.It standardizes all users into the same weekly bucket regardless of when they signed up
- d.It ensures retention measures each cohort's return behavior relative to its own signup originCorrect
Why? this is the answer
Computing week_offset anchors every activity to the user's specific signup cohort, which is the defining requirement of cohort retention; option C describes grouping all users into calendar activity weeks, which is the classic global active users trap that fails to measure cohort-specific return behavior.
Just read this? Test yourself on what you have been reading.
Read the original → stratascratch.com
- #sql
- #cohort-analysis
- #retention
- #data-modeling
- #growth
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on sql — each one lists the topics its interview covers.
See open roles