Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Churn After First Month

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

Your question is SQL Churn After First Month. 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

Given two tables (users and transactions), write a query to identify users who churned after their first month.

Treat a user's first month as the calendar month containing their earliest non-null transaction date. A user churns when they have no transaction in the immediately following calendar month.

Output

  1. One row per churned user with user_id, user_name, and first_month.
  2. Order by first_month ascending, then user_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTUnique user identifier
user_nameVARCHAR(100)User display name
transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
user_idINTUser associated with the transaction
transaction_dateDATEDate the transaction occurred
Tablesuserstransactions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results