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.
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.
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
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.