Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Detect Overlapping Subscription Periods
00:00
5 left

Detect Overlapping Subscription Periods

HardSQL · PostgreSQL

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
Interviewer

Your question is Detect Overlapping Subscription Periods. Start with the requirements and the one table 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.