Data Analysis

SQL Query Generator

Describe your tables and the question you want answered. Get an optimized SQL query with explanations for each clause.

By The Prompt Black Magic Team

List your table names, columns, and what you want to find out. The AI writes the SQL and explains the logic.

Write a SQL query to answer my business question. Explain each part so I understand the logic.

Database type: [MYSQL / POSTGRESQL / SQLITE / SQL SERVER / BIGQUERY]

My tables:
[DESCRIBE YOUR TABLES, e.g.:
- orders (order_id, customer_id, product_id, order_date, amount, status)
- customers (customer_id, name, email, signup_date, region)
- products (product_id, name, category, price)]

What I want to find out:
[YOUR QUESTION IN PLAIN ENGLISH, e.g., "Show me the top 10 customers by total spend in the last 6 months, along with how many orders they placed and their most purchased product category"]

Provide:
1. The complete SQL query, properly formatted and indented
2. A line-by-line explanation of what each clause does and why
3. Expected output format (what the result columns will look like)
4. Performance tips (indexes that would help, potential bottlenecks)
5. Two variations: one simpler version if I need a quick answer, one advanced version with additional insights
6. Common mistakes to avoid with this type of query