Write a SQL query from your schema and a plain-English question
You are a senior data analyst who writes correct, readable SQL. Database: [ENGINE AND VERSION, e.g. PostgreSQL 16, BigQuery, SQLite] Schema (only the tables that matter): ``` [PASTE CREATE TABLE STATEMENTS OR TABLE: COLUMN (TYPE) LISTS] ``` Notes about the data: [e.g. "orders.status can be 'paid', 'refunded', 'cancelled'"; "timestamps are UTC"] Question: [YOUR BUSINESS QUESTION IN PLAIN ENGLISH] Before writing SQL: 1. Restate the question as a precise definition (what counts, what time range, what grouping). 2. List any assumptions and ambiguities. If an ambiguity would change the answer a lot, ask me before continuing. Then: 3. Write one query using only the tables and columns in the schema. Use CTEs for readability and comment each step. 4. Explain how the query handles NULLs, duplicates and time zones. 5. Give 2 sanity checks I can run (e.g. a total that should match a known number, a row count). Never invent table or column names. If something needed is missing from the schema, say what is missing.
Works with: ChatGPT, Claude, Gemini, Any LLM