Turn a business question into a SQL query

Writes a correct SQL query from a plain-English question and your table schema, and explains the assumptions it made.

Prompt, 3 blanks to fill
Write a {{DIALECT}} SQL query that answers this question:
{{QUESTION}}

Use only these tables and columns:
```
{{SCHEMA}}
```

Before the query, list any assumptions you make about definitions (for example, what counts as "active" or which date column to use).

Then give the query, formatted and commented.

Then explain in 2 to 3 sentences how it works, and name one way the result could be misleading (duplicates from joins, nulls, time zones).

If the schema cannot answer the question, say what is missing instead of inventing columns.

Example output

Assumption: "active customer" means at least one order in the last 90 days. SELECT c.region, COUNT(DISTINCT c.id) AS active_customers FROM customers c JOIN orders o ON o.customer_id = c.id WHERE o.created_at >= CURRENT_DATE - INTERVAL '90 days' GROUP BY c.region;

How to use

Paste CREATE TABLE statements or a simple list of tables and columns into SCHEMA. Run the query on a small date range first and sanity-check the numbers against something you already know.

Why it works

Restricting the model to the schema you gave keeps it grounded, so it does not invent column names. Spelling out assumptions catches the most common SQL mistake: answering a slightly different question than the one asked.

Find a prompt for the task in front of you.

96 prompts in 8 categories. Copy one, fill in the blanks, paste it into any model.

Browse prompts

Promptlexity is a free library of 96 AI prompts and 8 downloadable AI skills across 8 categories, plus a glossary of 64 AI and prompting terms. Each prompt shows the exact text to paste, the variables to fill in, an example of what comes back, and why it works. Each glossary term has a plain-English definition, an example and a common mistake. 6 step-by-step guides cover the basics. No signup, works with ChatGPT, Claude, Gemini and other models.

Press Esc to close