Cohort Retention in 20 Lines of SQL
A 20-line SQL query builds a cohort retention table; remove DISTINCT and retention shows 150 percent.
Video #124 ยท SQL and analytics
Steps in the video
Files
- events.py (31 lines)
- retention.py (23 lines)
- run.py (24 lines)
Tested with
Python 3.12.15
What this does not show
Thirty made-up users with chances picked by hand, checked only in SQLite, where active means any event.
Sources
Learning IT by Example.