Write the SQL and explain what it will do
Produces the query plus how it will actually execute at your row counts.
Write a query for this. Question: [WHAT I WANT TO KNOW] Schema: [PASTE RELEVANT TABLES] Row counts: [ROUGH SIZES] Give me: 1. The query. 2. **In plain English, what it does step by step** — which table it starts from, what it joins, what it groups. 3. **How it will perform** at those row counts, and which index makes the difference. If a needed index does not exist, say so. 4. **What it will do wrong** if the data is messier than the schema implies — nulls where you expected values, duplicates, orphaned rows. If the question is ambiguous — and counting questions usually are, because "active users" means three different things — ask before writing rather than picking one.
Highlighted parts are placeholders. Replace them before you send.
Worked example
The input is invented for this page. The output shows what the prompt asks for with that input.
Example input (invented)
Question: The total of paid orders per calendar month in 2025, by the date each order was paid, and how many different customers paid in each month.
Schema
customers (
id bigint primary key,
email text not null,
created_at timestamptz not null
)
orders (
id bigint primary key,
customer_id bigint references customers(id),
status text not null,
total_cents integer not null,
paid_at timestamptz
)
Row counts: customers about 40,000. orders about 900,000, roughly 300,000 of them paid in 2025.
Example output
SELECT date_trunc('month', paid_at) AS month,
SUM(total_cents) / 100.0 AS revenue,
COUNT(DISTINCT customer_id) AS paying_customers
FROM orders
WHERE status = 'paid'
AND paid_at >= '2025-01-01'
AND paid_at < '2026-01-01'
GROUP BY 1
ORDER BY 1;
What it does. It starts from orders and joins nothing, because the customer id is already on the order. It keeps the rows with status paid whose paid_at falls in 2025 and cuts each paid_at down to the first day of its month. Per month it adds up the totals and counts each customer once.
How it will perform. The schema shows no index besides the primary keys, so the query reads all 900,000 orders to keep about 300,000. That is acceptable for a report you run by hand. An index on orders (paid_at) limits the read to 2025. It does not exist yet.
What it will do wrong.
- A paid order with no
paid_atis left out without a warning. customer_idcan be null. Such an order adds torevenueand not topaying_customers.- A month without paid orders is missing from the result. It does not appear with a zero.
paid_athas a time zone, so month edges follow the session's zone. An order paid at 23:30 UTC on 31 January counts as February in a session set to Berlin time.- An order that was paid and later set to
refundeddisappears from its month.
More Data prompts
3 of the 5 other prompts filed under Data.
Design a schema from a description
Turns a domain in prose into tables, keys and the constraints that protect them.
Explain and fix a spreadsheet formula
Understand a formula you inherited, then repair it.
Extract structured data from messy text
Pulls fields into JSON and marks what was missing instead of inventing it.
Data tools and skills
1 tool and 3 skills are filed under Data, the same category as this prompt.
Julius AI
Chat with a spreadsheet and get analysis plus charts.
Data cleaner
Profiles a messy dataset and proposes fixes before changing anything.
Data table analyst
Reads a table and reports what changed, with the caveats left in.
Migration safety checker
Finds the database migrations that will lock a table or break running code.