Back to Prompt Library
Data Analysis
SQLreportingdata analysisbusiness intelligencequeries

SQL Report Builder

A clean, commented SQL report query with CTEs, performance notes, and a plain-English walkthrough of the logic.

Prompt Template

Write a SQL query (or set of queries) to produce the following report: [REPORT_DESCRIPTION]. Database: [DATABASE_TYPE — e.g., PostgreSQL, BigQuery, Snowflake, MySQL]. Available tables and their relevant columns: [TABLE_SCHEMA_DESCRIPTION]. Report requirements: (1) Metrics to calculate: [METRICS_LIST], (2) Dimensions to group by: [DIMENSIONS], (3) Filters to apply: [FILTERS — e.g., date range, active users only, specific regions], (4) Sort order: [SORT_ORDER], (5) Output format: [OUTPUT_FORMAT — e.g., one row per day per segment / one summary row per user]. Write the query with: (a) clear CTE (Common Table Expression) structure for readability — break complex logic into named steps, (b) inline comments on any non-obvious logic, (c) a note on expected query performance and any indexes that should exist for efficiency. After the query, provide a plain-English explanation of what each CTE or major section does. If any requirement is ambiguous or the schema appears to be missing data, flag it with a [QUESTION: ...] comment in the code.

How to use this prompt

  1. Copy the prompt template using the button above.
  2. Paste it into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.).
  3. Replace all bracketed placeholders like [TOPIC] with your specific details.
  4. Send the prompt and refine the output as needed.
Advertisement