Subscription Growth Rate

ASKED IN INTERVIEW
4pts
Netflix, Spotify

Problem Statement

For subscription-based services, tracking growth speed is vital for assessing market health. You are tasked with calculating the Month-over-Month (MoM) growth rate of paid subscribers.

Write an SQL query to calculate the growth rate for each month.

Rules:

  • Only consider users with an active status.
  • Growth Rate Formula: ((Current Month Count - Previous Month Count) / Previous Month Count) * 100.
  • For the first month in the dataset, the growth rate should be NULL as there is no previous month to compare.
  • Output columns: month_start_date, current_subscribers, previous_subscribers, mom_growth_percentage.
  • Round the mom_growth_percentage to 2 decimal places.
  • Results must be returned in ascending order by month_start_date.

Table Schema:

  • Subscriptions: sub_id, user_id, start_date (DATE), status (active, cancelled), plan_type.
Tests your understanding of
Window Functions, LAG, Arithmetic and DateTime

Input Tables

Subscriptions
user_id(INTEGER)start_date(DATE)status(VARCHAR)
12026-01-05active
22026-01-12active
32026-01-20active
42026-01-25active
52026-02-02active
62026-02-14active
72026-02-28active
82026-03-05active
92026-03-15active

Expected Output

month_start_date(DATE)current_subscribers(INTEGER)previous_subscribers(INTEGER)mom_growth_percentage(DECIMAL)
2026-01-014nullnull
2026-02-0134-25
2026-03-0123-33.33

Tags

MediumASKED IN INTERVIEWWindow FunctionsLAGArithmeticDateTime
15-20 min
52%

Hints