Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Detect Overlapping Subscription Periods

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

Your question is Detect Overlapping Subscription Periods. Start with the requirements and the one table 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

You are given subscription records for customer accounts. Write a PostgreSQL query that identifies every pair of subscriptions for the same account whose active date ranges overlap, including cases where one subscription starts on the same day another ends. Return the account, both subscription IDs, and the overlapping date range.

Schema

subscriptions
ColumnTypeDescription
subscription_idPKINTPrimary key for the subscription record
account_idINTCustomer account identifier
plan_nameVARCHAR(100)Subscription plan name
start_dateDATESubscription start date
end_dateDATESubscription end date, nullable for open-ended subscriptions
Tablessubscriptions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results