โ Joins
โ GROUP BY
โ HAVING
โ CASE WHEN
โ CTEs
โ Subqueries
โ Window Functions
โ LAG()
โ LEAD()
โ Date Functions
โ Conditional Aggregation
๐ Business KPIs You Can Build
๐ Monthly Recurring Revenue (MRR)
๐ Annual Recurring Revenue (ARR)
๐ Average Revenue Per User (ARPU)
๐ Customer Lifetime Value (CLV)
๐ Monthly Customer Churn Rate
๐ Revenue Churn Rate
๐ Customer Retention Rate
๐ New Customers, New MRR
๐ Expansion MRR, Contraction MRR, Churned MRR
๐ Net Revenue Retention (NRR), Gross Revenue Retention (GRR)
๐ Upgrade Rate, Downgrade Rate
๐ Plan-wise Revenue, Active Subscriptions, Cancelled Subscriptions
๐ Payment Success Rate, Failed Payment Rate
๐ Monthly Revenue Growth, Revenue Contribution by Plan
๐ Customer Segmentation
๐ก Example 1: Calculate MRR
SELECT
SUM(p.monthly_price) AS mrr
FROM subscriptions s
JOIN plans p ON s.plan_id = p.plan_id
WHERE s.subscription_status = 'Active';
๐ก Example 2: Revenue by Plan
SELECT
p.plan_name,
COUNT(s.subscription_id) AS active_subscriptions,
SUM(p.monthly_price) AS monthly_revenue
FROM subscriptions s
JOIN plans p ON s.plan_id = p.plan_id
WHERE s.subscription_status = 'Active'
GROUP BY p.plan_name
ORDER BY monthly_revenue DESC;
๐ก Example 3: Identify Churned Customers
SELECT
customer_id,
subscription_id,
end_date
FROM subscriptions
WHERE subscription_status = 'Cancelled';
๐ก Example 4: Calculate Upgrade vs Downgrade Count
SELECT
change_type,
COUNT(*) AS total_changes
FROM subscription_changes
GROUP BY change_type;
๐ก Example 5: Calculate Average Revenue Per Customer
SELECT
ROUND(SUM(p.monthly_price) / COUNT(DISTINCT s.customer_id), 2) AS arpu
FROM subscriptions s
JOIN plans p ON s.plan_id = p.plan_id
WHERE s.subscription_status = 'Active';
๐ก Example 6: Rank Customers by MRR
WITH customer_mrr AS (
SELECT
s.customer_id,
SUM(p.monthly_price) AS mrr
FROM subscriptions s
JOIN plans p ON s.plan_id = p.plan_id
WHERE s.subscription_status = 'Active'
GROUP BY s.customer_id
)
SELECT
customer_id,
mrr,
DENSE_RANK() OVER (ORDER BY mrr DESC) AS revenue_rank
FROM customer_mrr;
๐ฏ Key Insights You Can Derive
๐น Which subscription plan generates the most revenue?
๐น Which plan has the highest churn?
๐น How much MRR comes from new customers?
๐น How much revenue is lost through cancellations?
๐น Which customers have upgraded or downgraded?
๐น Is revenue growing month over month?
๐น Which customers contribute the most recurring revenue?
๐ผ This project is especially useful for Data Analysts, Product Analysts, Revenue Analysts, Growth Analysts, and Business Intelligence professionals working with SaaS and subscription-based businesses.
Double Tap โค๏ธ For More