AI SQL Query Generator

Write down your table structure and the question you want answered. Entro writes the SQL in chat and explains it line by line, and you run it on your own database.

Write a query for PostgreSQL. My tables: customers(id, name, city) and orders(id, customer_id, order_date, amount). I want the 10 customers who spent the most in the last 90 days, along with their order count and average order amount. Leave out customers with no orders. Explain the query line by line and tell me which index would help.

Blue parts are the places to fill in with your own details. Tab selects the next one, Enter sends, Shift and Enter starts a new line.

This tool runs on Entro.

Example results

Get queries written, explained and tuned

Describe the tables, get the query

Type the table and column names or paste your CREATE TABLE output, then ask the question in plain words. Entro writes the query with your column names, whether it takes a JOIN, a GROUP BY, a subquery or a window function.

Written for your dialect

Date functions, row limits and string concatenation differ between dialects. Say whether you use PostgreSQL, MySQL, SQLite or SQL Server and the query comes in that syntax. Translating a query from one dialect to another happens in the same chat.

Have an existing query explained

Paste a long query someone else wrote and ask what it does. Entro walks through the subqueries and joins in order, suggests a more readable version that returns the same result, and points out which columns might benefit from an index.

Designing a schema from scratch

Describe the tables for a booking system or stock tracking in plain sentences. Entro writes the CREATE TABLE statements with primary and foreign keys, constraints and the indexes they need. It explains why it split something into its own table and adds a few sample INSERT rows for you to try.

No database connection, no access to your data

Entro doesn't reach your database and doesn't run the query. It sees only the table structure you type and any sample rows you paste. You run the query in your own database client. For a query with UPDATE or DELETE, try the same condition as a SELECT first and run it inside a transaction.

What people ask for most in SQL

  • Monthly revenue, best-selling products, change from the previous month, customers who bought again after their first order. List the columns you want in the result and the query is built around them.

SQL queries Entro has written

  • sql
    SELECT 
        c.id AS customer_id,
        c.name AS customer_name,
        c.city,
        COUNT(o.id) AS total_orders,
        ROUND(SUM(o.amount), 2) AS total_spent,
        ROUND(AVG(o.amount), 2) AS avg_order_amount
    FROM customers c
    JOIN orders o ON c.id = o.customer_id
    WHERE o.status != 'cancelled'
      AND o.order_date >= CURRENT_DATE - INTERVAL '90 days'
    GROUP BY c.id, c.name, c.city
    ORDER BY total_spent DESC
    LIMIT 10;
    

    Write a query for PostgreSQL. Tables: customers(id, name, city), orders(id, customer_id, order_date, amount, status). List the 10 customers who spent the most in the last 90 days, with their order count and average order amount. Leave out orders whose status is "cancelled". Explain the query line by line.

  • sql
    WITH monthly_revenue AS (
        SELECT
            DATE_FORMAT(order_date, '%Y-%m') AS order_month,
            SUM(amount) AS total_revenue
        FROM orders
        GROUP BY DATE_FORMAT(order_date, '%Y-%m')
    ),
    revenue_with_lag AS (
        SELECT
            order_month,
            total_revenue,
            LAG(total_revenue) OVER (ORDER BY order_month ASC) AS previous_month_revenue
        FROM monthly_revenue
    )
    

    Write a query for MySQL 8. From the orders(id, order_date, amount) table, work out total revenue for each month and the percentage change from the previous month. Use the LAG window function to get the previous month, and leave the change empty for the first month. Sort with the newest month first and round the percentage to one decimal.

  • sql
    -- Extensions
    CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
    
    -- 1. Customers
    CREATE TABLE customers (
        id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
        first_name VARCHAR(50) NOT NULL,
        last_name VARCHAR(50) NOT NULL,
        email VARCHAR(255) NOT NULL UNIQUE,
        phone VARCHAR(20) NOT NULL,
        created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
    );
    
    -- 2. Staff
    

    Write a PostgreSQL schema for a hair salon's booking system, with tables for customers, staff, services and appointments. An appointment belongs to one customer, one staff member and one service, and the same staff member can't have two appointments with the same start time. Include primary and foreign keys, the indexes it needs and three rows of sample data.

  • sql
    PRAGMA foreign_keys = ON;
    
    -- 1. Suppliers
    CREATE TABLE suppliers (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
        name TEXT NOT NULL,
        contact_email TEXT,
        phone TEXT,
        created_at TEXT NOT NULL DEFAULT (datetime('now'))
    );
    
    -- 2. Products
    CREATE TABLE products (
        id INTEGER PRIMARY KEY AUTOINCREMENT,
    

    Write an SQLite schema for a small shop's stock tracking: products, suppliers and stock_movements tables. A movement is either in or out, and its quantity must be greater than zero. Add a VIEW that works out each product's current stock from the movements, and write the query that lists products whose stock has dropped below 5.

  • sql
    SELECT 
        email, 
        COUNT(*) AS record_count
    FROM customers
    WHERE email IS NOT NULL
    GROUP BY email
    HAVING COUNT(*) > 1
    ORDER BY record_count DESC;
    

    Write queries for SQL Server. The customers(id, name, email, created_at) table has duplicate records sharing the same email. First write a query that shows how many times each email appears, then one that keeps the oldest record for each email and deletes the rest. Also give the SELECT version that shows which rows would be removed.

  • sql
    CREATE INDEX idx_orders_customer_status_date 
    ON orders (customer_id, status, order_date DESC);
    

    This PostgreSQL query is slow: SELECT * FROM orders WHERE customer_id = 42 AND status = 'shipped' ORDER BY order_date DESC LIMIT 20; The table has a large number of rows and the only index is on id. Explain why the query might be slow, write the CREATE INDEX statement for a suitable index and say why you chose that column order.

How to write an SQL query with AI

  1. 1

    Write your tables and your question

    Replace the highlighted parts above with your own table names and question, and say which database you use. Sending it opens the Entro chat. Without an account you sign up first, and your request is kept.

  2. 2

    Read the query

    Entro puts the query in a code block with the explanation underneath. If a condition doesn't match what you expect, say so in the same chat, for example "don't count cancelled orders".

  3. 3

    Run it on your own database

    Press Copy and run the query in your database client. If you get an error message or a result you didn't expect, paste it into the chat and Entro corrects the query.

Frequently asked questions

Does Entro connect to my database and run the query?

No. Entro doesn't connect to any database and doesn't run the queries it writes. It never asks for connection details or a password, and you have no reason to type them into the chat. You copy the query and run it in your own database client. Paste the result or the error message and the fix continues from there.

How do I tell Entro about my tables?

The quickest way is to type table and column names, such as orders(id, customer_id, order_date, amount). For a more exact result, paste your CREATE TABLE output or attach the .sql file; up to 3 files fit in one message. If the schema is a diagram, attach a screenshot. Column types and which fields can be null both affect the query.

Which databases does it write for?

It writes PostgreSQL, MySQL, SQLite and SQL Server syntax. Name yours at the start of the request, since date handling and row limits vary by dialect. If you're on an older version, mention that too, because some features such as window functions are missing from older releases.

How do I know the query returns the right result?

Entro doesn't run the query, so it can't see the result, and a logic error may remain. Try the query first on a small set of data you can count by hand. You can also ask Entro for a few sample rows plus the output it expects from them, then compare with what you get.

Can it speed up a slow query?

It can suggest, and it can't measure. Paste the query, the structure of the tables involved and the EXPLAIN output if you have it; Entro describes the likely cause and proposes an index or a rewrite. Whether the suggestion really helps is something you see by running the query again on your own data and checking the time.

Is it safe to use the UPDATE and DELETE queries?

Read every query that changes data before you run it. Put the same WHERE condition into a SELECT and check how many rows it touches. Run the query inside a transaction and don't commit until you've seen the result. Make sure you have a backup before trying it on a live database; Entro can't vouch for a query it never ran.

Do I need to paste my real data?

No. The table structure is usually enough to write a query. If you'd like to show sample rows, swap personal details such as customer names and phone numbers for made-up values. What you type is sent with your message, and the chat history is kept in your account.

Can Entro set up a database for me?

The chat writes schemas and queries; it doesn't create a database or its tables. You run the CREATE TABLE statements on your own database. The database of a site you built in Entrobase is a separate matter, managed from the Database page, and Entro takes you there if you ask.

Is the SQL query generator free?

The Entro chat is available on the Free plan too. Each query you ask for counts toward your plan's AI usage limit; the limit depends on the plan and is shown on the pricing page. It opens in the browser and needs no extension installed on your database.

More AI tools

  • AI Python Code Generator

    Describe the task and Entro writes the Python in chat: pandas clean-ups, automation scripts, API calls. It explains the code and helps you fix errors.

  • AI JavaScript Code Generator

    Entro writes the JavaScript for your form, button or list right in chat. It explains console errors and updates old code to async/await. You run it.

  • AI TypeScript Code Generator

    Turn JSON into types, add types to a JavaScript file and get compiler errors explained. Entro writes the TypeScript in chat; you compile it yourself.

  • AI Coding Assistant

    Entro writes, explains, debugs and translates code in chat. Need a whole site or app? Builder creates the project and you download the code as a ZIP.

  • Digital Wallet App: Digital wallet

    AI App Builder

    Describe your app and Entrobase builds a first version for iPhone and Android. Try it on your phone, change it by chatting, then build the Android file.

  • AI HTML Code Generator

    Entro writes HTML and CSS in chat for a form, a table, an email template or a single-file page. Copy the code, save it and open it in your browser.

You describe it, Entrobase builds it.

Create with Entrobase