SQL Report Query Builder
The SQL Report Query Builder translates plain English data requests into production-ready SQL queries. Instead of spending time constructing complex joins, subqueries, and window functions, you describe what report you need and get a query you can run immediately.
Data analysts, business intelligence professionals, and product managers who know basic SQL use this template when building ad-hoc reports, answering stakeholder questions, or exploring datasets. It handles common patterns like year-over-year comparisons, cohort breakdowns, funnel analysis, and ranking queries.
The prompt produces well-structured SQL with clear aliasing, proper join conditions, and inline comments explaining each section. It also includes a sample output table so you can verify the query's logic before running it against your actual database.
This prompt is just the starting point
Score it with AI, optimize it with one click, track versions, and build your prompt library.
The Prompt
Generate a SQL query for the following report: **Database System**: [PostgreSQL / MySQL / SQL Server / BigQuery / SQLite] **Report Description**: [DESCRIBE IN PLAIN ENGLISH WHAT DATA YOU NEED, e.g., "Monthly revenue by product category for the last 12 months, with month-over-month growth percentage"] **Tables Available** (list table names and key columns): ``` [e.g., orders (id, user_id, product_id, amount, created_at, status) products (id, name, category, price) users (id, email, signup_date, country)] ``` **Filters or Conditions**: [ANY SPECIFIC FILTERS, e.g., "Only completed orders, exclude test accounts"] Generate: 1. **The SQL Query**: Write a clean, well-formatted query with: - Descriptive column aliases (e.g., `total_revenue` not `sum1`) - Comments explaining complex logic (CTEs, window functions, subqueries) - Proper NULL handling where relevant - Date functions appropriate for the specified database system - ORDER BY clause that makes the output immediately useful 2. **Expected Output Preview**: Show a sample table with 3-5 rows of realistic (fictional) data so I can verify the query logic matches my intent. 3. **Performance Note**: If the query could be slow on large datasets, suggest an optimization (index hint, materialized view, or query restructure). 4. **Variations**: Suggest 1-2 simple modifications (e.g., "Change GROUP BY to weekly instead of monthly" or "Add a WHERE clause to filter by country").
Usage Tips
- List your actual table and column names: The more accurate your schema description, the more likely the query runs without edits. Include data types if relevant (especially for date columns).
- Specify your database system: Date functions, string concatenation, and window function syntax differ between PostgreSQL, MySQL, and BigQuery. Specifying yours avoids syntax errors.
- Start simple, then iterate: Ask for the base report first, then follow up with "Now add a rolling 7-day average" or "Now break this down by user segment". Building incrementally produces cleaner SQL.
- Verify with the expected output: Compare the sample output table against what you expect. If the columns or grouping look wrong, you can correct the prompt before running the query.
Get more from this prompt
Save it, score it with AI, optimize it, and track every version. Free to start.