Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Membership Churn

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL for Membership Churn. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Amazing Lash Studio wants a monthly view of membership churn based on activity in its reservation logs. Write a PostgreSQL query for January through April 2025.

A member counts in the monthly active base when they have at least one completed reservation during the month and their membership was active on the reservation date. A member counts as churned when their membership cancellation date falls in that same month.

Requirements

  1. Return one row per month, including months with no qualifying reservations.
  2. Show active members, churned members, and churn rate as a percentage rounded to two decimals.
  3. Exclude cancelled, no-show, and NULL-status reservations.
  4. Prevent division by zero and order results chronologically.

Schema

memberships
ColumnTypeDescription
membership_idPKINTEGERUnique membership identifier
member_idINTEGERStable identifier for the member
member_nameVARCHAR(100)Member name
start_dateDATEMembership activation date
cancellation_dateDATEMembership cancellation date
reservation_logs
ColumnTypeDescription
reservation_idPKINTEGERUnique reservation identifier
membership_idINTEGERMembership associated with the reservation
reservation_dateDATEDate of the reservation
reservation_statusVARCHAR(20)Reservation outcome
Tablesmembershipsreservation_logs
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results