Back to Practice
#0103
Cohort Month Zero
MediumSQL25 min20 XP
Problem
Given events(user_id, event_date), return user_id and cohort_month, the YYYY-MM of each user first event. Sort by user_id.
Why This Matters
Cohorts start with a first-seen date. Retention and lifecycle analysis build on this step.
Schema
events(user_id INTEGER, event_date TEXT)
Examples
Example 1
Inputuser 1 events in Jan and Feb
Outputuser 1 cohort_month Jan
Cohort is based on the first event date.
Constraints
- Return the exact structure requested.
- Handle the edge cases mentioned in the prompt.
- Prefer clear logic over clever one-liners.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputuser 1 events in Jan and Feb
Expecteduser 1 cohort_month Jan
Cohort is based on the first event date.
Hidden Test Categories
one event per userunordered eventssame first month ties