Converts a natural-language data requirement plus a table schema into a syntactically correct SQL query for a named database, with its assumptions stated up front.
Version 1 · 3 variables · 2 required
Fill in the values below — the customized prompt updates as you type. marks a required value.
Describe the result set in plain language: which rows, which aggregations, which filters, what order.
Tables with their columns, and key relationships if known. e.g. orders(id, customer_id, order_date, status)
e.g. PostgreSQL 15, MySQL 8.0, SQL Server 2022, BigQuery, SQLite Default: PostgreSQL 15
Fill in What you want the query to return, Schema to copy the customized prompt.
Copy the prompt and open a model site to paste it. PromptByte never sends your prompt anywhere — providers do not accept pre-filled prompts through a link.
**Assumptions**
- `order_items.order_id` joins to `orders.id`, and `products.category_id` joins to `categories.id`. These are inferred from the naming convention, since no foreign keys were listed.
- "Last 90 days" is measured against `orders.order_date` relative to today, inclusive of today.
- Revenue is `quantity * unit_price` summed over line items; there is no discount or tax column in the schema, so none is applied.
- Cancelled orders are excluded. If `status` uses different values than `'cancelled'`, adjust the filter.
- `COUNT(DISTINCT o.id)` is used rather than `COUNT(*)` because the join to `order_items` multiplies order rows by line item.
**Query**
```sql
SELECT c.name AS category,Showing all 1 public result from GPT-5.5 on version 1.
**Assumptions**
- `order_items.order_id` joins to `orders.id`, and `products.category_id` joins to `categories.id`. These are inferred from the naming convention, since no foreign keys were listed.
- "Last 90 days" is measured against `orders.order_date` relative to today, inclusive of today.
- Revenue is `quantity * unit_price` summed over line items; there is no discount or tax column in the schema, so none is applied.
- Cancelled orders are excluded. If `status` uses different values than `'cancelled'`, adjust the filter.
- `COUNT(DISTINCT o.id)` is used rather than `COUNT(*)` because the join to `order_items` multiplies order rows by line item.
**Query**
```sql
SELECT c.name AS category,
COUNT(DISTINCT o.id) AS order_count,
SUM(oi.quantity * oi.unit_price) AS total_revenue
FROM orders AS o
JOIN order_items AS oi ON oi.order_id = o.id
JOIN products AS p ON p.id = oi.product_id
JOIN categories AS c ON c.id = p.category_id
WHERE o.order_date >= CURRENT_DATE - INTERVAL '90 days'
AND o.status <> 'cancelled'
GROUP BY c.id, c.name
HAVING COUNT(DISTINCT o.id) > 50
ORDER BY total_revenue DESC;
```
Grouping by `c.id` as well as `c.name` keeps the result correct if two categories share a display name. If `order_date` is a timestamp rather than a date, cast it (`o.order_date::date`) or the boundary day will be partially excluded.Contributor notes: Illustrative example — not an actual model run. Written to show the shape of a good answer so the prompt can be judged before you spend a call on it. Attribution: adapted from https://github.com/f/prompts.chat by f (Fatih Kadir Akın), licensed CC0-1.0. Source file: https://github.com/f/prompts.chat/blob/main/PROMPTS.md
Reports go to moderators and are never shown publicly.
No public results yet
Check join cardinality and aggregation grain to explain duplicate rows or double-counted measures before changing a reporting query.
No public results yet
Specify temporal evaluation, leakage checks, baselines and business-relevant metrics before judging a forecasting model.
No public results yet
Review a chart's scales, labels, aggregation and claims, separating visual issues from data questions that need verification.
No public results yet
Label supplied comments consistently while preserving mixed opinions, unclear cases and the exact words supporting each label.
No public results yet
Produce a deterministic transformation from repeated measure columns to tidy rows with explicit keys, types and missing-value rules.
No public results yet
Specify cohort membership, return behavior and observation maturity so retention percentages remain comparable.
Oldest first · one level of replies
Sign in to join the discussion. Share what you learned or made with this prompt.
No comments yet
Be the first to share how this prompt worked for you.