◯ Free: 5 uses/day • Resets in 16h 13m
Development & Technical

SQL Query Generator

Plain-English question in, a correct SQL query for your database out — with your schema respected and every clause explained.

Learn more

The SQL Query Generator turns a question — 'monthly revenue per country for 2025, only customers with more than three orders' — into a query written for the database you run: PostgreSQL, MySQL and MariaDB, SQLite, SQL Server, BigQuery or Snowflake. Paste your tables and columns and the query uses exactly those names; leave the schema empty and it states the assumptions it made. You choose the style (readable CTEs, compact, or analytical with window functions) and how much explanation you want, and every answer ends with the shape of the result and the indexes that would make it fast. It never writes destructive statements unless you ask for them.

0 / 4000
0 / 10000

✓ Free to use — no signup, no credit card.

All audiences

Monthly revenue per country, active customers only

A finance report with a HAVING-style customer filter

See input + output preview

Input

What should the query return?
Monthly revenue per country for 2025, counting only customers who placed more than 3 orders in 2025. Sort by month, then revenue descending.
Tables and columns (optional)
orders(id, customer_id, total_cents integer, created_at timestamp) customers(id, country text, signup_at timestamp)
SQL dialect
PostgreSQL
Query style
Readable (CTEs, one clause per line)
Explanation
Brief

Output (excerpt)

```sql
WITH active_customers AS (
  SELECT o.customer_id
  FROM orders AS o
  WHERE o.created_at >= DATE '2025-01-01'
    AND o.created_at <  DATE '2026-01-01'
  GROUP BY o.customer_id
  HAVING COUNT(*) > 3
)
SELECT
  DATE_TRUNC('month', o.created_at)::date AS month,
  c.country,
  SUM(o.total_cents) / 100.0            AS revenue
FROM orders AS o
JOIN active_customers AS a ON a.customer_id = o.customer_id
JOIN customers        AS c ON c.id = o.customer_id
WHERE o.created_at >= DATE '2025-01-01'
  AND o.created_at <  DATE '2026-01-01'
GROUP BY 1, 2
ORDER BY month, revenue DESC;
```

**Schema used as given.**

The CTE finds customers with more than three orders in 2025; the main query keeps only their orders, truncates each order to its month and sums revenue per month and country. The date range is half-open so 31 December is counted once…
Developers

Latest order per customer

A window-function query replacing a correlated subquery

See input + output preview

Input

What should the query return?
For every customer, their most recent order with its total and date.
Tables and columns (optional)
orders(id, customer_id, total_cents integer, created_at timestamp) customers(id, email text)
SQL dialect
MySQL / MariaDB
Query style
Analytical (window functions where useful)
Explanation
Detailed (clause by clause)

Output (excerpt)

```sql
WITH ranked AS (
  SELECT
    o.customer_id,
    o.id          AS order_id,
    o.total_cents,
    o.created_at,
    ROW_NUMBER() OVER (PARTITION BY o.customer_id ORDER BY o.created_at DESC, o.id DESC) AS rn
  FROM orders AS o
)
SELECT c.id AS customer_id, c.email, r.order_id, r.total_cents / 100.0 AS total, r.created_at
FROM customers AS c
JOIN ranked AS r ON r.customer_id = c.id AND r.rn = 1
ORDER BY r.created_at DESC;
```

**Schema used as given.**

| Clause | What it does |
|---|---|
| `ROW_NUMBER() OVER (PARTITION BY … ORDER BY created_at DESC, id DESC)` | numbers each customer's orders newest first; the id tiebreak makes the result deterministic |
| `JOIN ranked … AND r.rn = 1` | keeps exactly one row per customer |…

Your SQL Query Generator results will appear here

Expect clean code blocks with comments, plus a short explanation of what changed.

How to Use SQL Query Generator

  1. Write the question the way you would ask a colleague: what rows, which filters, which grouping, which order.
  2. Paste your tables and columns if you have them — one table per line with its columns in brackets. The query then uses your real names and needs no editing.
  3. Pick the dialect you run; date functions, LIMIT versus TOP and quoting all differ between PostgreSQL, MySQL, SQLite, SQL Server, BigQuery and Snowflake.
  4. Choose 'Detailed' explanation when you are learning or reviewing someone else's request, 'Query only' when you know what you asked for.

Use Cases

1

Answer a business question from an analyst without waiting for the data team

2

Turn a reporting request into a query that respects the real schema of the warehouse

3

Rewrite a slow query into a readable CTE version with the indexes it needs

4

Translate a query from MySQL to PostgreSQL or BigQuery when migrating

5

Draft the SELECT that previews what an UPDATE or DELETE would touch before running it

Tips for Best Results

  • Include the column types in the schema (created_at timestamp, total_cents integer) and the query handles dates and money correctly.
  • Say 'only' and 'at least' explicitly — 'customers with more than 3 orders' becomes a HAVING clause, not a WHERE.
  • For a dashboard, ask for the analytical style: window functions avoid the self-joins that make reports slow.
  • Read the performance section; it names the index that turns a full table scan into a lookup.

Frequently Asked Questions

Which databases are supported?

PostgreSQL, MySQL and MariaDB, SQLite, SQL Server (T-SQL), BigQuery and Snowflake. The query uses that dialect's own functions and syntax — date truncation, LIMIT or TOP, quoting and string aggregation all differ, and the output is written for the one you selected.

Do I have to paste my schema?

No, but it helps. With a schema the query uses your exact table and column names and needs no editing. Without one, the tool assumes a minimal plausible schema and lists every assumption above the explanation so you can correct it.

Will it write a DELETE or UPDATE?

Only when you explicitly ask for a modification. Even then it wraps the statement in a transaction and puts the SELECT that previews the affected rows first, so you can check before you commit.

How does it handle dates and money?

Dates use the dialect's native truncation and comparison functions, and ranges are written as half-open intervals so no day is counted twice. Money stored as integer cents stays integer until the final division, and the result shape says which unit each column is in.

Is the query guaranteed to be fast?

It is written to be correct first and readable second, and every answer ends with the indexes that would make it fast and the constructs that would prevent index use. Run it against a realistic data volume before scheduling it — only your database knows its statistics.

🔒
Your Privacy is Protected

We keep your input and the result for up to 90 days to run the service, prevent abuse and, if you're signed in, show your history. They are processed by the AI providers listed in our Privacy Policy. We don't sell them.

Related tools

Try this agent

API Automation AgentDescribe an automation in plain English → REST/webhook recipe → curl + Python + Node samples…Try this agent →

Related workflow

Plan & Spec FeaturesFrom user story to technical specRun workflow →

Read more