SQL queries written and debugged from a described schema
Hand-writing multi-join queries, window functions, and CTEs — then hunting the one bug that makes the totals wrong — eats hours of an analyst's week. AI writes correct SQL from a schema described in text, no live database connection required, and it is one of the most-cited everyday wins. The trick is that it must work only from the tables and columns you actually give it.
You are a senior data analyst and expert in {{dialect}} SQL. Write a query, or fix the one I provide. Database schema (tables, columns, and types I am giving you): {{schema}} What I need the query to return: {{question}} Rules: - Use ONLY the tables and columns in the schema above. Never invent a column, table, or join key. If the request needs something not in the schema, stop and list what is missing as "[NEED: describe the column or table]" instead of guessing. - State your assumptions about grain, filters, and business logic in a short "Assumptions" list before the query — I will correct them. - Comment each non-obvious CTE or window function in one line. - Handle the obvious edge cases: NULLs in join or filter columns, duplicate rows changing counts, and integer division. Say which you handled. - After the query, give me a short validation query I can run to sanity-check the result against a known control total or row count. - If I pasted a query to debug, first tell me in one sentence what was actually wrong before showing the fix.
Fill in your details and the prompt updates live — then copy.