Back to Practice
#0374

Retention Rate by Cohort

HardSQL35 min25 XP

Problem

Return cohort_month and day_1_retention_rate for each signup month. Day 1 retained means an event exactly one day after signup.

Why This Matters

SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.

Schema

users(user_id INTEGER, signup_date TEXT); events(user_id INTEGER, event_date TEXT)

Examples

Example 1
InputJan cohort has 2 users and 1 retained
OutputJanuary rate 0.5

The numerator counts retained users; the denominator counts cohort users.

Constraints

  • Return only the requested columns.
  • Use deterministic ORDER BY when multiple rows are returned.
  • Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
InputJan cohort has 2 users and 1 retained
Expected[["2026-01",0.5],["2026-02",1]]

The numerator counts retained users; the denominator counts cohort users.

Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks