BeginnerCoder

Lesson 25 — Ultimate: cohort report

Boss level: a cohort report

A cohort is a group of users who started at the same time — for example, everyone who signed up in January. A cohort report shows, per signup month, how many users there are and how many were still active later. Build it with a CTE for each user's signup month, a LEFT JOIN to activity, and COUNT(DISTINCT ...) so a user active many times counts once.

COUNT(DISTINCT CASE WHEN a.month = '2026-03' THEN u.id END)

(CASE without ELSE gives NULL, and COUNT skips NULLs.)

Why it matters: "do the users we got in January stick around?" is the key growth question for any app — this is how analysts answer it.

Want it another way?
Task

Fill in the active_in_march column the same way as active_in_feb. Expected: Jan cohort 3 users, 2 in Feb, 1 in March.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with SQL Deep Dive

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.