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.
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.