SQL query builder: AI prompt for data science
A ready-to-run prompt for coding assistance work in data science. It assigns the AI a specific senior role, takes your details as variables, and defines the output format — so the first result is usable, not a warm-up.
What this prompt does
Act as a senior analytics engineer. It structures the request the way experienced practitioners brief a colleague: context first, then explicit deliverables, then quality constraints.
Best for
Data Science professionals — and anyone doing this work — who need coding assistance handled to a professional standard for analysts and business stakeholders. Typical moments: experiment reviews, model handoffs and stakeholder readouts.
Before you use it
Have these details ready to replace the highlighted variables:
[SQL dialect][business question][paste schema]
The prompt
Act as a senior analytics engineer. Write a [SQL dialect] query that answers: [business question]. Tables and schemas: [paste schema]. Requirements: CTEs over subqueries, comments explaining each step, correct handling of NULLs and duplicates, and a final sanity-check query to validate the result. Then explain the query in plain English for a non-technical stakeholder.
Quality checklist before you run it
- Paste actual code and errors, not summaries of them
- Run and test suggested code before committing
- Never paste secrets, keys or proprietary data you can't share
Common mistakes
- Running the prompt with [variables] left unfilled
- Accepting the first output instead of iterating once or twice
- Skipping fact-checks on names, numbers and claims
When to use it — and when not to rely on it
Use it whenever coding assistance would otherwise start from a blank page. Don't rely on it as a finished product: outputs need your judgment, your facts, and — in regulated work — professional review.
Related prompts
All Data Science prompts · All Coding Assistance prompts · Search the full library