Consulta SQL a partir de um esquema
Escreve uma consulta SQL para uma pergunta, usando apenas as tabelas e colunas do esquema que você fornece.
Use quando: Você sabe o que quer perguntar aos dados, mas não os 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>Variáveis
{{question}}- A pergunta a responder.
{{schema}}- As instruções CREATE TABLE ou uma lista de tabelas com colunas e tipos.
{{dialect}}- O banco de dados, por exemplo PostgreSQL ou BigQuery.
Entrada de exemplo
question: monthly revenue per country for 2025
schema: orders(id, customer_id, total, created_at); customers(id, country)
dialect: PostgreSQLSaída de exemplo
```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;
```Ilustrativa: escrita para mostrar a forma esperada, não gerada por um modelo.