CHURN Rate calculation for codflex
For the numerator, we only want the portion of the customers who cancelled during January:
For the denominator, we only want to be considering customers who were active at the beginning of January:
When dividing, we need to be sure to multiply by
1.0
to cast the result as a float:SELECT 1.0 *
(
SELECT COUNT(*)
FROM subscriptions
WHERE subscription_start < '2017-01-01'
AND (
subscription_end
BETWEEN '2017-01-01' AND '2017-01-31'
)
)/(
SELECT COUNT(*)
FROM subscriptions
WHERE subscription_start < '2017-01-01'
AND (
(subscription_end >= '2017-01-01')
OR (subscription_end IS NULL)
)
)
AS result;
Comments
Post a Comment