Monthly Cohort Retention for New ExtraCare Loyalty Members

Last updated: November 29, 2026

Quick Overview

Using extracare_members (member_id, enrolled_at) and store_transactions (member_id, txn_ts, amount), build a cohort table showing, for each enrollment month, the share of members who made a purchase in each of months 0 through 6 after enrolling.

CVS Health
Data Manipulation (SQL/Python)
Data Scientist
CVS Health
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Using extracare_members (member_id, enrolled_at) and store_transactions (member_id, txn_ts, amount), build a cohort table showing, for each enrollment month, the share of members who made a purchase in each of months 0 through 6 after enrolling.

CVS ExtraCare is one of the largest retail loyalty programs in the US, and retail analytics teams track whether new members keep shopping after the signup offer. This tests cohort construction with month offsets and the correct denominator.

What the Interviewer Expects
  • Assigns each member to a cohort by enrollment month
  • Computes month offset between purchase month and cohort month
  • Counts distinct active members per cohort and offset
  • Divides by full cohort size, not by active members
  • Mentions right censoring for recent cohorts
Key Topics to Cover
cohort analysis
DATE_TRUNC
month offset
retention curve
censoring
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you show revenue retention instead of member retention?
  • Recent cohorts have fewer observable months. How do you present them?
  • How would you split cohorts by acquisition channel (in store vs app)?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data
  • Cohort = calendar month of enrolled_at.
  • Active in offset k = at least one transaction with positive amount in the k-th calendar month after the cohort month (month 0 is the enrollment month).
  • ...
Approach
  1. Build a cohort CTE with each member's cohort month and cohort size.
  2. Join transactions, compute month_offset from year and month differences.
  3. Count distinct members per cohort and offset in ...

Submit Your Answer
Markdown supported