Apple Music Cancellation Rate by Plan
For each Apple Music plan type, what is the total number of subscribers, how many have cancelled, and what is the cancellation rate?
- Aggregation
- CASE expressions
- Numeric functions
- NULL handling
- Sorting
Challenge brief
Understand the request
Apple Music Retention is investigating churn patterns by plan type to decide where to invest in retention campaigns.
Compute cancellation rate per plan type using conditional aggregation and percentage calculation.
Return
- plan_type
- total_subs
- cancelled
- cancel_rate_pct (rounded 1, % of total)
Constraints
- Count cancelled subscriptions within each plan population
- The rate calculation must remain safe for an empty denominator
- Show the highest cancellation rates first, then subscriber count, then plan type
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
apple_music_subscriptions
plan_typeVARCHAR(30)statusVARCHAR(20)
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
All data is in apple_music_subscriptions. GROUP BY plan_type. Use SUM(CASE WHEN status = 'cancelled' THEN 1 ELSE 0 END) to count cancellations within each group. Divide by COUNT(*) for the rate.
Hint 2
SUM(CASE WHEN status = 'cancelled' THEN 1 ELSE 0 END) AS cancelled. Multiply by 100.0 (not 100) and divide by COUNT(*) for floating-point percentage. ROUND to 1 decimal.
Hint 3
Build question 20 from its business grain: identify the driving rows, add only valid relationships, then apply the required filtering, aggregation, and deterministic ordering.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT plan_type, COUNT(*) AS total_subs, SUM(CASE WHEN status = 'cancelled' THEN 1 ELSE 0 END) AS cancelled, ROUND(SUM(CASE WHEN status = 'cancelled' THEN 1 ELSE 0 END) * 100.0 / NULLIF(COUNT(*), 0), 1) AS cancel_rate_pct FROM apple_music_subscriptions GROUP BY plan_type ORDER BY cancel_rate_pct DESC, total_subs DESC, plan_typeWhy this works
Multiplying by 100.0 ensures floating-point division. David Brown's Individual subscription is the only cancelled one — 1 of 3 Individual subscribers = 33.3%. Family and Student plans have no cancellations. Single-table query — no JOIN needed.
Success check
3 plans — Individual has 33.3% churn (1 of 3), Family and Student have 0% churn
Expected result
Use this output to verify values, aliases, ordering, and row count.
| plan_type | total_subs | cancelled | cancel_rate_pct |
|---|---|---|---|
| Individual | 3 | 1 | 33.3 |
| Family | 2 | 0 | 0 |
| Student | 1 | 0 | 0 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Microsoft
Independent Microsoft-style cloud, productivity, subscription, usage, support, and customer analytics 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.