Querydrill

Level 5: Interview classics Exercise 124 of 161 Hard Product analytics

Monthly churn rate

An SQL exercise from Querydrill. Solve it with a SQL editor in your browser, checked on the rows it returns and again on changed data, and it is checked the moment you submit.

Try it yourself

A user is active on a day when one of their subscriptions started on or before that day and has no end date or an end date after that day. Return one row for March 2025: the number of users active on 2025-03-01, how many of them were no longer active on 2025-04-01, and that share as a percentage rounded to 1 decimal.

subscriptions (10 rows)

iduser_idplanstart_dateend_date
11basic2025-01-102025-03-10
22pro2025-01-15NULL
33basic2025-01-202025-02-20
44pro2025-02-012025-04-01
53pro2025-03-15NULL
65basic2025-02-102025-03-10
76basic2025-03-01NULL
81pro2025-03-10NULL
97pro2025-03-202025-03-25
105basic2025-04-052025-05-05

Free, no account needed. PostgreSQL runs in your browser and your answer is checked again on changed data.

What this exercise teaches

Churn is about people, not subscription rows. A user who changes plan has a subscription that ends but is still a customer. Comparing who is active at the start with who is active at the end handles that correctly.

A hint if you get stuck

Build the set of active users on each of the two dates, then LEFT JOIN the first set to the second.

Background you need

Common mistakes on this exercise

  • Counts every subscription that ended in March as churn, also for a user who only changed plan or who joined and left within the month.
  • Treats the end date itself as still active, so a subscription that ends on 1 April is not counted as churned.

Each of these returns a result that looks plausible. The checker catches them because it runs your query on changed data as well.

Keep going on the practice page

Your first 8 exercises on Querydrill are free, with no account. The practice page has the full editor, timed mode and all the exercises in order. A free account shows 3 reference solutions a day; Pro unlocks every exercise, every solution, timed mode and the certificate.

Open this exercise

More practice on the same topic

More exercises in Interview classics