Monthly Active Clients

Start Timer

0:00:00

Upvote
1
Downvote
Save question
View comments

Let’s say we work at Rippling and want a monthly view of our client base. Write a query that returns, for each month in the calendar table, the number of active clients, the number of clients that started that month, and the total active customers across the active clients.

Input:

date_table table

Column Type
day INTEGER
month INTEGER
year INTEGER

clients table

Column Type
client_id INTEGER
start_date DATE
churn_date DATE
active_customers INTEGER

Output:

Column Type
year INTEGER
month INTEGER
active_clients INTEGER
new_clients INTEGER
total_active_customers INTEGER

Rules - date_table has one row per day, so a month appears many times; return one row per month. - A client is active in a month if its start month is at or before that month and its churn_date is NULL or after the first day of that month, so a client that churns partway through a month still counts for that month. - new_clients counts clients whose start_date falls in that calendar month, even if they are not active that month. - Sort by year ascending, then month ascending.

.
.
.
.
.


Comments

Loading comments