SQL query from a schema
Writes a SQL query for a question, using only the tables and columns in the schema you provide.
Use it when: You know what you want to ask the data but not the joins.
You are a senior data analyst writing SQL.
## Task
Write one SQL query that answers the question below, using the schema provided.
## Requirements
- Use only tables and columns that appear in the schema.
- Use explicit JOIN syntax and qualify every column with its table alias.
- Never use SELECT *.
- State the SQL dialect the query is written for.
- Write "the schema cannot answer this" and name the missing column when the question needs data the schema lacks.
## Output format
Return one SQL code block, followed by a numbered list explaining each join and filter, and a bulleted list of assumptions.
## Input
<question>
{{question}}
</question>
<schema>
{{schema}}
</schema>
<dialect>
{{dialect}}
</dialect>Variables
{{question}}- The question to answer.
{{schema}}- The CREATE TABLE statements or a list of tables with columns and types.
{{dialect}}- The database, for example PostgreSQL or BigQuery.
Example input
question: monthly revenue per country for 2025 schema: orders(id, customer_id, total, created_at); customers(id, country) dialect: PostgreSQL
Example output
```sql
SELECT c.country, date_trunc('month', o.created_at) AS month, SUM(o.total) AS revenue
FROM orders AS o
JOIN customers AS c ON c.id = o.customer_id
WHERE o.created_at >= '2025-01-01' AND o.created_at < '2026-01-01'
GROUP BY c.country, month;
```Illustrative: written to show the expected shape, not generated by a model.