SQL Query Writer for Business Reports

Generate SQL queries for common business reporting needs — revenue trends, cohort analysis, funnel metrics, and more.

Prompt Template

You are a data engineer specializing in business analytics. Write SQL queries for the following report:

Database: [PostgreSQL / MySQL / BigQuery / Snowflake]
Report type: [e.g., monthly revenue by product, cohort retention, funnel conversion]
Tables available: [list tables and key columns]
Time period: [e.g., last 90 days, year-to-date]
Filters needed: [e.g., only US customers, exclude test accounts]
Grouping: [e.g., by week, by region, by plan tier]
Metrics needed: [specific numbers you want]

Provide:
1. The SQL query (with comments explaining key sections)
2. How to interpret the output
3. Any indexes that would speed up this query
4. A variation for month-over-month comparison

Example Output

Monthly Revenue by Product Tier — PostgreSQL

SELECT

DATE_TRUNC('month', o.created_at) AS month,

p.tier,

COUNT(DISTINCT o.customer_id) AS paying_customers,

SUM(o.amount_cents) / 100.0 AS revenue_usd,

ROUND(AVG(o.amount_cents) / 100.0, 2) AS avg_order_value

FROM orders o

JOIN products p ON p.id = o.product_id

WHERE

o.status = 'completed'

AND o.created_at >= DATE_TRUNC('year', CURRENT_DATE) -- YTD

AND o.test_mode = false -- exclude test accounts

GROUP BY 1, 2

ORDER BY 1 DESC, revenue_usd DESC;

**Interpretation:** Each row = one month + product tier combination. Compare `revenue_usd` across tiers to spot which tier drives growth.

Index recommendation:

CREATE INDEX idx_orders_created_status ON orders(created_at, status) WHERE test_mode = false;

MoM Comparison variation:

-- Add LAG() window function to compare with prior month

LAG(revenue_usd) OVER (PARTITION BY tier ORDER BY month) AS prev_month_revenue

Tips for Best Results

  • 💡Share your actual table and column names — generic column names like 'amount' vs 'amount_cents' cause bugs
  • 💡Ask for the query and then ask 'what edge cases could cause incorrect results?' — it catches subtle issues
  • 💡Always add `LIMIT 100` while testing, then remove it for the full run

Try it with

Frequently Asked Questions

What is the SQL Query Writer for Business Reports prompt?

Generate SQL queries for common business reporting needs — revenue trends, cohort analysis, funnel metrics, and more. It's a free ChatGPT prompt template from our Data Analysis collection — copy it, fill in the bracketed variables, and paste it into your AI tool.

Which AI tools work with this prompt?

It's written and tested for ChatGPT and Claude. Any AI assistant that accepts free-form text prompts will handle it well.

How do I customize this ChatGPT prompt?

Replace the bracketed variables — such as [list tables and key columns], [e.g., last 90 days, year-to-date], [e.g., by week, by region, by plan tier] — with your own details before running it. Share your actual table and column names — generic column names like 'amount' vs 'amount_cents' cause bugs

Is this prompt free to use?

Yes. Every prompt on PromptAtlas is free to copy, customize, and use — no signup required.