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 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.
| Column | Type | Description |
|---|---|---|
| subscription_idPK | INT | Primary key for the subscription record |
| account_id | INT | Customer account identifier |
| plan_name | VARCHAR(100) | Subscription plan name |
| start_date | DATE | Subscription start date |
| end_date | DATE | Subscription end date, nullable for open-ended subscriptions |