Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
SQL for Membership Churn
00:00
5 left

SQL for Membership Churn

MediumSQL · PostgreSQL

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
Interviewer

Your question is SQL for Membership Churn. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.