Plan Revenue Summary
Return plan, subscriber_count, revenue, and revenue_per_subscriber for each plan, ordered by revenue descending.
- Subqueries
- Aggregation
- Numeric functions
- NULL handling
- Sorting
Challenge brief
Understand the request
Finance — Unit Economics Finance is building a unit-economics dashboard and needs ARPU (average revenue per user) alongside headcount and total revenue per plan.
Show subscriber count, total revenue, and revenue per subscriber for each plan.
Return
- plan
- subscriber_count
- revenue
- revenue_per_subscriber
Constraints
- Return subscriber count, revenue, and average revenue per subscriber for each plan
- Protect the ratio when a plan has zero subscribers
- Order by revenue descending, then plan
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
subscriptions
planVARCHAR(20)monthly_feeINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Build subscriber count and revenue at plan grain first.
Hint 2
Protect the count before using it as a ratio denominator.
Hint 3
Round the derived metric and order plans deterministically.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
WITH sub_counts AS (SELECT plan, COUNT(*) AS subscriber_count, SUM(monthly_fee) AS revenue FROM subscriptions GROUP BY plan) SELECT plan, subscriber_count, revenue, ROUND(revenue * 1.0 / NULLIF(subscriber_count, 0), 2) AS revenue_per_subscriber FROM sub_counts ORDER BY revenue DESC, planWhy this works
The CTE computes headcount and revenue in one pass. The outer SELECT derives revenue_per_subscriber by dividing the two aggregated values. CAST(revenue AS FLOAT) prevents integer division truncation in SQLite.
Success check
Returns the complete deterministic result for plan revenue summary
Expected result
Use this output to verify values, aliases, ordering, and row count.
| plan | subscriber_count | revenue | revenue_per_subscriber |
|---|---|---|---|
| Premium | 3 | 60 | 20 |
| Standard | 4 | 60 | 15 |
| Basic | 3 | 24 | 8 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Meta
Independent Meta-style social-product, engagement, content, community, messaging, and advertising SQL practice.
Airbnb
Independent Airbnb-style marketplace, booking, listing, payment, review, and guest analytics SQL practice.
Return to the complete interview preparation experience.