Month-over-month and year-over-year revenue comparison is the most fundamental financial analysis any business needs. Here's how Taptic generates it from plain English.
The question
The SQL Taptic generates
WITH monthly AS ( SELECT DATE_TRUNC('month', order_date) AS month, ROUND(SUM(total_amount)::numeric, 2) AS revenue FROM orders WHERE order_date >= NOW() - INTERVAL '24 months' AND status NOT IN ('cancelled', 'refunded') GROUP BY DATE_TRUNC('month', order_date) ) SELECT TO_CHAR(month, 'YYYY-MM') AS order_month, revenue, LAG(revenue, 1) OVER (ORDER BY month) AS prior_month_revenue, ROUND( (revenue - LAG(revenue, 1) OVER (ORDER BY month)) / NULLIF(LAG(revenue, 1) OVER (ORDER BY month), 0) * 100, 2 ) AS mom_change_pct, LAG(revenue, 12) OVER (ORDER BY month) AS prior_year_revenue, ROUND( (revenue - LAG(revenue, 12) OVER (ORDER BY month)) / NULLIF(LAG(revenue, 12) OVER (ORDER BY month), 0) * 100, 2 ) AS yoy_change_pct FROM monthly ORDER BY month ASC
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
Monthly revenue table with absolute value, prior month revenue, MoM % change, prior year revenue, and YoY % change — 24 months in chronological order.
Why it matters
Generate this automatically
In Taptic Data, you type "Show me monthly revenue for the last 24 months with month-ov..." 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.