Write SQL Queries from a Plain-English Question and Your Table Schema
Paste your schema and ask a question in plain English. You get a working SQL query, a line-by-line explanation, and a row-count check query to verify the results.
You getMain query, line-by-line explanation and sanity-check query
Prompt
You are a senior data analyst who writes clear, correct SQL for business reporting.
I will paste my table schema (table names, columns, data types, keys) right after this prompt, then ask a question in plain English. If I have not named my SQL dialect (PostgreSQL, MySQL, SQL Server, BigQuery, SQLite), ask first. If my question is ambiguous, for example which date column defines a period or whether to include cancelled records, ask up to 3 short numbered questions in one message and wait for my answers.
Rules:
1. Use only tables and columns in my schema. If something you need is missing, say so instead of guessing a name.
2. Use explicit JOIN ... ON syntax and table aliases. Do not use SELECT *.
3. Flag every one-to-many join that could duplicate rows and explain how the query handles it.
4. Handle NULLs and date ranges explicitly. For timestamps, use >= start and < end, not BETWEEN.
5. Write a separate sanity-check query that counts rows at each step (base table, after filters, after each join).
Output format:
1. Assumptions (bullets)
2. Main query (one code block)
3. Line-by-line explanation (numbered, one line per clause)
4. Sanity-check query (code block) and the result pattern to expect
5. Two ways to extend the query
End with one line on what in my data could still make the result wrong.Example output
Tips and common edits
Why this works
- Limiting the model to columns in your schema stops it from inventing table or column names that break the query.
- Requiring flags on one-to-many joins catches the most common cause of inflated totals.
- The step-by-step row-count query lets you verify the logic before you trust or share the numbers.
Use this when you need a report query but are unsure about the joins or filters. Have your table and column names ready, ideally the CREATE TABLE statements. Works in ChatGPT, Claude or Gemini.
Common edits
- Ask for the same query in a second dialect, such as converting PostgreSQL to SQL Server.
- Request a version that writes results to a view or temporary table for reuse in Excel or Power BI.
Prompt details
- By
- Prompts-GPT editors
- Published
Did this prompt work?
Keep exploring
More like this
Build an Excel Sales Forecast Comparing Moving Average and FORECAST.ETS
You get a tested Excel sales forecast with paste-ready formulas for two methods, a MAPE comparison on held-out months, and a clear pick of the better method.
Calculate Year-over-Year and Month-over-Month Growth in Excel Without Misleading Percentages
You get a growth table, exact Excel formulas that handle zero and negative baselines and partial months, plain-language takeaways, and a list of percentages that would mislead.
Plan a Pivot Table That Answers a Specific Business Question
Get a pivot table plan mapping your fields to rows, columns, values and filters, with aggregation choices, data shape fixes and build steps.
Summarize Pasted Spreadsheet Data into Key Findings and Trends
Paste rows from Excel or Google Sheets and get numbered findings tied to exact figures, a trend table, data quality flags and the gaps that limit conclusions.
Write a Weekly or Monthly KPI Report Narrative from Your Excel Numbers
Turns your pasted KPI numbers into a report narrative where each metric states the change, the likely driver and a next action, with every claim tied to a figure.
Build a Power Query Workflow That Combines and Cleans Monthly Excel Files
You get numbered Power Query steps with paste-ready M code, a full query, and a flag on every step that breaks when column names change.