Guide 4/15/2026

SQL Query: Calculate Customer Lifetime Value (LTV)

#calculate customer lifetime value sql#sql query for ltv#customer lifetime value formula sql#sql query to group orders by customer#measure customer profitability sql
Quick Answer
SELECT customer_id, SUM(order_amount) AS total_revenue, COUNT(order_id) AS total_orders, SUM(order_amount) / COUNT(order_id) AS average_order_value FROM orders GROUP BY customer_id

Calculating Customer Lifetime Value (LTV) is critical for understanding your business profitability. This SQL query works by grouping your transaction data by customer ID and aggregating their total spend against their total order count to derive a personalized Average Order Value (AOV).

By running this query on your orders table, you can quickly identify your high-value segments and adjust your marketing strategy accordingly. Whether you are using PostgreSQL, MySQL, or SQL Server, this snippet provides the foundation for accurate financial reporting and customer segmentation.

Ready to try it?

Use our SQL Query Generator to generate perfect results in seconds.

Open SQL Query Generator