Active Subscriptions
Which users have active subscriptions right now, and which products are they subscribed to?
- Date analysis
- NULL handling
- Filtering
- Sorting
Challenge brief
Understand the request
Subscriptions Operations needs a roster of all currently active subscriptions — those with no end date — to reconcile billing records.
List all active subscriptions (end_date IS NULL) showing user_id and product_id.
Return
- user_id
- product_id
Constraints
- A null end date identifies a currently active subscription
- Order by user ID and product ID
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
subscriptions
subscription_idINTEGERuser_idINTEGERproduct_idINTEGERstart_dateDATEend_dateDATEpriceINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Active subscriptions have no end date — end_date IS NULL in the subscriptions table. Filter to those rows. No JOIN needed since we only need user_id and product_id.
Hint 2
SELECT user_id, product_id FROM subscriptions WHERE end_date IS NULL.
Hint 3
Build question 4 from the required result grain: choose the driving table, add only the joins and filters needed for that grain, then apply aggregation and deterministic ordering.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT user_id, product_id FROM subscriptions WHERE end_date IS NULL ORDER BY user_id, product_id;Why this works
end_date IS NULL is the standard pattern for "currently active" in SCD tables. All 12 subscriptions in this dataset are active (no end dates set), so all rows are returned.
Success check
12 active subscriptions — every user in the dataset has exactly one active subscription
Expected result
Use this output to verify values, aliases, ordering, and row count.
| user_id | product_id |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
| 5 | 2 |
| 6 | 1 |
| 7 | 3 |
| 8 | 2 |
| 9 | 1 |
| 10 | 1 |
Previewing 10 of 12 expected rows. Run the query in the editor to inspect the full result.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Apple
Independent Apple-style product, retail, services, support, workforce, and device-usage SQL practice.
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Amazon
Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice.
Return to the complete interview preparation experience.