SQL-запрос по схеме
Пишет SQL-запрос на вопрос, используя только таблицы и столбцы из предоставленной вами схемы.
Используйте, когда: Вы знаете, что хотите спросить у данных, но не знаете, как соединять таблицы.
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>Переменные
{{question}}- Вопрос, на который нужен ответ.
{{schema}}- Операторы CREATE TABLE или список таблиц со столбцами и типами.
{{dialect}}- База данных, например PostgreSQL или BigQuery.
Пример ввода
question: monthly revenue per country for 2025
schema: orders(id, customer_id, total, created_at); customers(id, country)
dialect: PostgreSQLПример вывода
```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;
```Иллюстрация: написан, чтобы показать ожидаемую форму, а не создан моделью.