SQL Query Builder
Generate SQL queries from natural language descriptions
codingsqldatabasequery
Prompt Template
Write a SQL query that {description}.
Database schema:
{schema}
Requirements:
- Use {dialect} syntax
- Optimize for performance
- Add comments explaining complex logic
- Handle edge cases (NULLs, empty results)Variables
{description}Example: finds the top 10 customers by total order value in the last 30 days
{schema}Example: customers(id, name, email), orders(id, customer_id, total, created_at)
{dialect}Example: PostgreSQL
Example Output
```sql SELECT c.name, c.email, SUM(o.total) as total_spent FROM customers c JOIN orders o ON c.id = o.customer_id WHERE o.created_at >= NOW() - INTERVAL '30 days' GROUP BY c.id, c.name, c.email ORDER BY total_spent DESC LIMIT 10; ```
Tips
- Always provide the schema
- Specify the SQL dialect