Revenue by region is one of the most common business analysis questions across any industry. This is how Taptic's AI generates it from plain English against your actual schema.
The question
The SQL Taptic generates
WITH quarters AS ( SELECT region, SUM(CASE WHEN order_date >= DATE_TRUNC('quarter', CURRENT_DATE) AND order_date < DATE_TRUNC('quarter', CURRENT_DATE) + INTERVAL '3 months' THEN total_amount ELSE 0 END) AS current_quarter, SUM(CASE WHEN order_date >= DATE_TRUNC('quarter', CURRENT_DATE) - INTERVAL '3 months' AND order_date < DATE_TRUNC('quarter', CURRENT_DATE) THEN total_amount ELSE 0 END) AS prior_quarter FROM orders WHERE order_date >= DATE_TRUNC('quarter', CURRENT_DATE) - INTERVAL '3 months' GROUP BY region ) SELECT region, ROUND(current_quarter, 2) AS current_q_revenue, ROUND(prior_quarter, 2) AS prior_q_revenue, ROUND(current_quarter - prior_quarter, 2) AS change, ROUND( (current_quarter - prior_quarter) / NULLIF(prior_quarter, 0) * 100, 2 ) AS pct_change FROM quarters ORDER BY current_quarter DESC
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
A table of regions with current quarter revenue, prior quarter revenue, absolute change, and percentage change — sorted by current revenue descending.
Why it matters
Generate this automatically
In Taptic Data, you type "Show me total revenue by region for this quarter compared to..." 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.