Ask Claude about this

Monthly Customer Growth Rate Analysis

Business Context

As part of Netflix's growth metrics analysis, we need to track the month-over-month percentage change in our active customer base. This is a critical KPI that helps our executive team understand subscriber acquisition and retention trends, which directly impacts our revenue forecasting and content investment decisions.

Technical Requirements

The primary objective is to develop a PostgreSQL query for the following:

Task: Calculate the month-over-month percentage change in the number of active customers.

Definition of "Active Customer": A customer is considered active if they have a subscription with status 'active' on the last day of the month being analyzed.

Database Schema

-- Table: Subscriptions
CREATE TABLE Subscriptions (
    subscription_id INT PRIMARY KEY,
    user_id INT NOT NULL,
    status VARCHAR(50) NOT NULL, -- e.g., 'active', 'cancelled', 'pending'
    start_date DATE NOT NULL,
    end_date DATE -- NULL if the subscription is ongoing
);

Sample Data for Subscriptions Table:

subscription_id user_id status start_date end_date
1 101 active 2022-01-01 NULL
2 102 active 2022-01-15 NULL
3 103 cancelled 2022-01-20 2022-02-10
4 104 active 2022-02-05 NULL
5 105 active 2022-02-15 NULL
6 106 cancelled 2022-02-20 2022-03-05
7 107 active 2022-03-10 NULL
8 101 cancelled 2022-01-01 2022-03-20
9 101 active 2022-03-25 NULL

Note on Sample Row 8 & 9: The interpretation of how cancellations/re-subscriptions are logged can vary. For this problem, assume each row is a distinct subscription event or state. If user 101 cancels and then re-subscribes, there might be an update to the old record (adding an end_date) and a new record for the new subscription. The query should handle distinct users correctly based on their status on the last day of the month. The provided solution correctly handles this by looking at all subscription records that qualify.

Expected Output Format:

The final output should show the month (first day of the month, as DATE), the count of active customers for that month, and the percentage change from the previous month, rounded to two decimal places.

month (DATE) active_customers (BIGINT) percent_change (NUMERIC)
2022-01-01 2 NULL
2022-02-01 4 100.00
2022-03-01 4 0.00

Active Customer MoM Growth (PostgreSQL)

MODERATE

Write a PostgreSQL query to calculate the month-over-month percentage change in the number of unique active customers. A customer is defined as active if their subscription status is 'active' on the last day of the analyzed month, based on the Subscriptions table.

Your Turn! What are your thoughts on this problem or alternative ways to solve it? Share your own SQL query attempts or insights in the comments below!

Nerchuko Academy · Free DS Interview Prep