HomeQuery LibraryDatabase

Which regions are driving your revenue — and which are lagging?

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.

📊 Any SQL database👥 Business analysts at companies with regional sales data🔤 Plain-English → SQL
Part of the Explore all SQL query examples

This is part of the Taptic Data Database query library. Explore related queries: SQL query for monthly revenue trend, SQL query for top customers by revenue, SQL query for revenue by region, and more.

Show me total revenue by region for this quarter compared to last quarter
Revenue by Region Query — generated by Taptic Data AI
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
Schema-aware SQL generated from plain English28 lines

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. This type of analysis is commonly used in ai business analytics and sql server reporting.

Breaking it down line by line

  1. Uses a CTE with conditional SUM to calculate both quarters in a single pass over the data
  2. DATE_TRUNC('quarter') automatically handles the current quarter start regardless of the date
  3. CASE statements allow both quarters to be calculated in one GROUP BY — no UNION needed
  4. Final SELECT adds absolute and percentage change vs prior quarter
  5. NULLIF protects against division by zero for regions with no prior quarter revenue

Result description

A table of regions with current quarter revenue, prior quarter revenue, absolute change, and percentage change — sorted by current revenue descending.

The business impact

Regional revenue comparison is fundamental to territory management, resource allocation, and sales compensation. Seeing Q/Q change by region immediately surfaces which markets are accelerating and which need attention — information that typically takes days to compile manually.

All queries and use cases on this page relate to analyzing your Any SQL database data in Taptic. To see the full analytics workflow, explore ai business analytics, sql server reporting, text to sql tool.

Common questions

How do I generate a "Revenue by Region Query" query automatically?
In Taptic Data, type "Show me total revenue by region for this quarter compared to last quarter" and the AI generates schema-aware SQL against your real Any SQL database data — no manual writing required.
What database does this query work with?
This query is designed for Any SQL database. Taptic reads your live schema so the generated SQL always matches your actual table and column names.
Can I edit the generated SQL?
Yes. Taptic shows you the exact SQL it generated. You can edit it directly, ask the AI to explain any line, or request a revision in plain English.
Can I save this as a scheduled report?
Yes. Once you run this query in Taptic, you can save it as a report, add charts and KPIs, and schedule it to email your team on any cadence — daily, weekly, or monthly.

Skip the SQL. Ask the question.

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/mo

No credit card required. Connect your data source in under 5 minutes.

Next step
Run this query on your own SQL Server data
Connect 🗄️ SQL Server to Taptic Data and this SQL generates automatically from plain English — against your real schema, your real tables.
Analytics hub
More Database queries, use cases, and analytics resources in one place.
Explore all SQL query examples