Netflix-style Company ChallengeMediumVerified answerSQLite live

Revenue by Plan

Return plan and total_revenue (sum of monthly_fee) per plan, ordered by total_revenue descending.

  • Aggregation
  • Sorting

Challenge brief

Understand the request

Finance — Revenue Planning Finance is building the monthly revenue model and needs to know how much each plan tier contributes.

Calculate total monthly revenue generated by each subscription plan.

Return

  • plan
  • total_revenue

Constraints

  • Return one row per plan
  • 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

Monthly fee is stored on each subscription.

Hint 2

Aggregate fee values at plan grain.

Hint 3

Order by revenue and then by plan.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT plan, SUM(monthly_fee) AS total_revenue FROM subscriptions GROUP BY plan ORDER BY total_revenue DESC, plan

Why this works

SUM(monthly_fee) grouped by plan gives the total monthly contribution per tier. Premium and Standard both generate $60 total, so a secondary ORDER BY plan breaks the tie deterministically.

Success check

Returns the complete deterministic result for revenue by plan

Expected result

Use this output to verify values, aliases, ordering, and row count.

plantotal_revenue
Premium60
Standard60
Basic24

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Interview Practice

Return to the complete interview preparation experience.