SQL Playground
TutorialsPlayground
SQL FormatterSQL MinifierSyntax ValidatorJSON to SQLCSV to SQLSQL to JSONER Diagram Generator
Daily ChallengeInterviewsCheat SheetBlog

© 2026 SQL Playground. Built for developers.

PrivacyTermsAboutRSS Feed
SQL Playground
TutorialsPlayground
SQL FormatterSQL MinifierSyntax ValidatorJSON to SQLCSV to SQLSQL to JSONER Diagram Generator
Daily ChallengeInterviewsCheat SheetBlog
Back to Blog
2026-01-07
3 min read

Calculating Customer Lifetime Value (CLV) in SQL

sqlanalyticssaas-metricsclvbusiness-intelligence

Customer Lifetime Value (CLV or LTV) is arguably the most important metric in business. It answers: "How much can we afford to spend to acquire a customer?"

If your CLV is $500, you can profitably spend $100 on ads to get them. If your CLV is $50, spending $100 will bankrupt you.

Customer lifetime value curve with ARPU and churn formula
Customer lifetime value curve with ARPU and churn formula

1. Historical CLV (The Easy Way)

The simplest version is to just look at how much customers have already spent.

SELECT
    customer_id,
    SUM(amount) as lifetime_revenue
FROM orders
GROUP BY customer_id;

This is accurate but backward-looking. It doesn't tell you what a new customer is worth today.

2. Simple Predictive CLV (ARPU / Churn)

A common formula for subscription businesses (SaaS) is:

Formula:

CLV = (Average Monthly Revenue per User (ARPU)) / (Monthly Churn Rate)

If average users pay $10/month and 5% cancel every month, expected lifetime is $1 / 0.05 = 20$ months. $20 \times $10 = $200$ CLV.

Interactive Playground: Calculating ARPU and Churn

Let's calculate the inputs for this formula from raw subscription logs.

Interactive SQL
Loading...

Cohort-Based CLV

The most accurate way to measure CLV is via Cohorts. You group users by the month they joined (e.g., "Jan 2024 Cohort") and track their cumulative spend over time.

This requires pivot tables or complex self-joins, but it reveals trends like "Newer cohorts are spending less than older cohorts," which a simple average would hide.

Conclusion

CLV isn't just a number; it's a health check for your business model. SQL allows you to track this dynamic metric daily, giving you early warning signs if your customer value starts to degrade.

Share this article:

Related Articles

sqlanalytics

SQL for Data Analysis: The Ultimate Guide

Move beyond basic SELECTs. Master the core SQL techniques for real-world data analysis: Data Cleaning, Time-Series Analysis, Window Functions, and Cohort Analysis.

Read more
sqlanalytics

SQL Window Frames: ROWS vs RANGE

Learn how ROWS and RANGE window frames change results, avoid hidden pitfalls, and build correct moving calculations with clear, runnable examples.

Read more
sqlanalytics

Calculating Weighted Averages in SQL

Standard averages can be misleading. Learn how to calculate weighted averages in SQL to get more accurate insights from your data.

Read more
Previous

Sessionization: Grouping Events into User Sessions in SQL

Next

Data Masking and Anonymization Techniques in SQL

Comments

© 2026 SQL Playground. Built for developers.

PrivacyTermsAboutRSS Feed