SQL Query Builder prompt for Claude

Translate an analytics question into read-only SQL with an explicit row definition and checks for inflated counts.

Use the SQL Query Builder prompt

Copy the prompt into Claude and replace any sample inputs with your own.

Prompt
Build a read-only [dialect] query for [question] using [schema]. State the output grain, handle nulls and duplicate joins explicitly, and show how to check the totals. Suggest an index or plan check only when the query gives a reason for it.
Download Markdown

Decide what one row in the result represents

Supply the dialect, relevant tables and columns, and join keys. Define whether you want a row per customer, order, or day. A join from orders to line items can multiply the rows, so spell out whether customers or items belong in the metric.

Check the query against a small sample whose result you can calculate yourself. Inspect zero counts, null values, and customers with several orders. Review the plan before running a costly query on a large data warehouse.

Browse Prompts