Customer lifetime value is the metric that separates sustainable eCommerce businesses from ones that are just burning acquisition budget. This query calculates it directly from your Shopify orders.
This is part of the Taptic Data Shopify query library. Explore related queries: SQL query for Shopify revenue by month, SQL query for Shopify customer lifetime value, SQL query for Shopify refund rate by product, and more.
The question
The SQL Taptic generates
WITH customer_orders AS ( SELECT o.customer_id, COUNT(DISTINCT o.id) AS order_count, SUM(o.total_price) AS lifetime_value, MIN(o.created_at) AS first_order_date, MAX(o.created_at) AS last_order_date FROM shopify_orders o WHERE o.financial_status = 'paid' GROUP BY o.customer_id ), first_product AS ( SELECT DISTINCT ON (o.customer_id) o.customer_id, li.title AS first_product FROM shopify_orders o JOIN shopify_order_line_items li ON li.order_id = o.id ORDER BY o.customer_id, o.created_at ASC ) SELECT c.email, COALESCE(c.first_name || ' ' || c.last_name, c.email) AS customer_name, co.order_count, ROUND(co.lifetime_value::numeric, 2) AS lifetime_value, ROUND(co.lifetime_value::numeric / NULLIF(co.order_count, 0), 2) AS avg_order_value, fp.first_product, co.first_order_date::date AS first_order, co.last_order_date::date AS last_order, (co.last_order_date - co.first_order_date) / NULLIF(co.order_count - 1, 0) AS avg_days_between_orders FROM customer_orders co JOIN shopify_customers c ON c.id = co.customer_id LEFT JOIN first_product fp ON fp.customer_id = co.customer_id WHERE co.order_count >= 2 ORDER BY co.lifetime_value DESC LIMIT 100
This query was generated by Taptic Data from plain English against a real Shopify schema. In Taptic, you type the question — the AI writes the SQL, runs it, and returns the result. You can edit the SQL, ask for explanations, and save it as a refreshable report. This type of analysis is commonly used in shopify revenue dashboard and ecommerce reporting.
How this query works
What it returns
A ranked table of your best repeat customers showing lifetime value, order count, average order value, first product purchased, first/last order dates, and average repurchase frequency.
Why it matters
New to this metric? How to calculate Shopify customer lifetime value — definition, formula, and business context.
All queries and use cases on this page relate to analyzing your Shopify data in Taptic. To see the full analytics workflow, explore shopify revenue dashboard, ecommerce reporting.
FAQ
Generate this automatically
In Taptic Data, you type "Show me customer lifetime value — total spend, order count, ..." and this SQL runs automatically against your real Shopify data.
Try Taptic Free — $29.99/moNo credit card required. Connect your data source in under 5 minutes.
Related use cases
Compare tools