Text Analysis & GenerationEducationTechnology
SQL to Natural Language Explainer
Translate any SQL into a concise, structured explanation with labeled sections, explicitly stating joins, filters, constants, aggregations, outputs, and unknowns, using schema notes when available.
Prompt Content
Explain the SQL query below in clear natural language.
1. Read the SQL and schema notes.
2. Write the explanation using the exact output format below.
3. If schema notes are N/A, infer from names and mark unknowns.
Constraints:
• Natural language only; no SQL in the output.
• Be faithful to the query; do not propose rewrites.
• State constants, conditions, and join types explicitly.
• If something is unknown or dialect-specific, say "unknown".
• Keep it concise and complete.
Output format (use these labeled lines exactly, one line per item):
Purpose:
Sources & joins:
Filters & logic:
Aggregations/windows:
Output:
Notes:
<example>
SQL:
SELECT c.customer_id, COUNT(*) AS orders
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.status = 'completed' AND o.created_at >= '2024-01-01'
GROUP BY c.customer_id
ORDER BY orders DESC
LIMIT 10;
Explanation:
Purpose: List the top 10 customers by number of completed orders since 2024-01-01.
Sources & joins: orders joined to customers on customers.id = orders.customer_id (inner join).
Filters & logic: status = 'completed' and created_at >= 2024-01-01.
Aggregations/windows: COUNT(*) per customer_id; no window functions.
Output: columns customer_id, orders; sorted by orders desc; at most 10 rows; one row per customer.
Notes: Customers without completed orders are excluded by the inner join; NULL handling for status is not addressed.
</example>
SQL:
<sql-query>
Sql Query
</sql-query>
Schema notes:
<schema-notes>
Schema Notes
</schema-notes>
Variables
- Sql Query
- The SQL query to explain
- Example: SELECT user_id, AVG(total) AS avg_spend FROM orders WHERE status = 'paid' GROUP BY user_id ORDER BY avg_spend DESC LIMIT 5;
- Schema Notes
- Brief table/column definitions, keys, or business meaning relevant to the query (write N/A if unknown)
- Example: orders(user_id, total, status); users(id). users.id = orders.user_id; amounts in USD; timestamps UTC.