SQL Interview & Case Lab
Back to Business SQL Patterns

Calculating LTV in SQL — Patterns from Real SaaS

Three flavours of LTV you'll be asked to compute, and the SQL that gets each one right. FIND_VIDEO: search 'customer lifetime value SQL tutorial' — recommended channel: Data with Danny. Aim for 11 min or under.

15 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. CLV Overview — The instructor outlines customer segmentation goals and defines core metrics using AdventureWorks 2019.
  2. Schema Examination — Key columns across the Customer and SalesOrderHeader tables are reviewed for joins and aggregations.
  3. Aggregating Metrics — A query is built to group orders by customer ID, calculating order counts, AOV, and lifespan.
  4. Applying CLV Formula — Base metrics inside a CTE are multiplied together to calculate projected customer lifetime value.
  5. Profitability Segmentation — A CASE expression segments customers into non-profitable, profitable, and very profitable tiers.
PDF notes

Frequently asked questions

Why is lifespan calculated from the first purchase date instead of account creation date?

Order history measures active purchasing behavior, so the first order date accurately reflects the transactional lifespan start.

Why are customers with CLV below 1,000 classified as non-profitable?

Low lifetime spend often fails to cover the combined cost of customer acquisition (CAC) and account servicing.

What table provides the financial total for orders in AdventureWorks?

The `Sales.SalesOrderHeader` table contains the `TotalDue` column, which stores the complete amount owed per order.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.