Pareto principle holds for most B2B businesses — 20% of customers drive 80% of revenue. This query finds yours, including their order history and average deal size.
The question
The SQL Taptic generates
SELECT c.company_name, c.account_manager, COUNT(DISTINCT o.id) AS order_count, ROUND(SUM(o.total_amount)::numeric, 2) AS total_revenue, ROUND(SUM(o.total_amount)::numeric / NULLIF(COUNT(DISTINCT o.id), 0), 2) AS avg_deal_size, MIN(o.order_date)::date AS first_order, MAX(o.order_date)::date AS last_order, ROUND(SUM(o.total_amount)::numeric * 100 / SUM(SUM(o.total_amount)) OVER ()::numeric, 2) AS pct_of_total_revenue FROM orders o JOIN customers c ON c.id = o.customer_id WHERE o.order_date >= DATE_TRUNC('year', CURRENT_DATE) AND o.status NOT IN ('cancelled', 'refunded') GROUP BY c.id, c.company_name, c.account_manager ORDER BY total_revenue DESC LIMIT 20
This query was generated by Taptic Data from plain English against a real Any SQL database 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
Top 20 customers ranked by total revenue with order count, average deal size, first/last order dates, and percentage of total company revenue.
Why it matters
Generate this automatically
In Taptic Data, you type "Show me my top 20 customers by total revenue this year with ..." and this SQL runs automatically against your real Any SQL database data.
Try Taptic Free — $29.99/moNo credit card required. Connect your data source in under 5 minutes.