SQL query generator
Describe the question and name your tables. You get the query, and what it assumed about your schema.
A worked example
“Top 10 customers by revenue in the last 90 days”
SELECT c.name,
SUM(o.total) AS revenue,
COUNT(*) AS orders
FROM orders o
JOIN customers c ON c.id = o.customer_id
WHERE o.created_at >= NOW() - INTERVAL '90 days'
GROUP BY c.name
ORDER BY revenue DESC
LIMIT 10;It joins each order to its customer, keeps the last 90 days, then totals by customer name and returns the ten largest. The order count comes along because a customer with one large order and a customer with forty small ones are different situations that this figure alone would hide.
What it assumes
- Groups by name, so two different customers with the same name are merged into one row. Group by c.id and select the name alongside it if that is possible in your data.
- NOW() is the server's clock and includes the time of day, so this is the last 90 days to the second rather than the last 90 calendar days. Use CURRENT_DATE for whole days.
- Counts orders as they stand today. Refunded or cancelled orders are included unless your orders table excludes them already.
01
Date arithmetic is where dialects diverge.
The interval syntax that works in Postgres is a syntax error in SQL Server, and BigQuery wants a third form. Picking your database changes the query rather than adding a comment to it.
02
It only uses the tables you named.
If you paste your schema it works from that. If you do not, it invents the smallest plausible one and the first caveat tells you exactly what it assumed, so you can see whether the query means anything for your database.
03
It never runs against anything.
There is no connection to configure and no credential to hand over. The query is text you take to your own client, which is also why an UPDATE comes back with a note telling you to run it as a SELECT first.
Questions people ask
Do I have to give you my database schema?
No, but the query is much more useful if you do. Paste your table and column names into the second field and the query will reference the real ones. Without them it invents a plausible schema and says so in the first caveat.
Does it connect to my database?
No. There is no connection, no credential, and no way for this page to reach your data. You get SQL as text and run it yourself in whatever client you already use.
Will it write an UPDATE or a DELETE?
If you clearly ask for one, yes, with its WHERE clause and a caveat telling you to run it as a SELECT first to see which rows it touches. If you did not ask for one, it writes a SELECT.
Which dialect should I pick?
The one you actually run. It matters most for dates and for string handling, which is where the same query is valid in one database and a syntax error in another.
When it is a whole file
A formula fixes one column. If what you actually have is four exports and a question, drop them here and you get the cleaned data, the analysis and the charts back.
No account needed to start. You only pay when you like what you see.