SQL
SQL Query From a Plain-English Ask
Translate a business question into SQL with joins, grain warnings, and a check query.
The Prompt
sql-query-from-a-plain-english-ask.md
Write SQL for this question. State grain and join assumptions. Question: {{question}} Warehouse / dialect: {{dialect}} Tables I have (names + key columns): {{schema}} Filters: {{filters}} Need: {{need}} Return: 1. Assumptions (grain, time zone, inclusive dates) 2. The query, readable CTEs, no SELECT * 3. How I should sanity-check the result (counts or a duplicate check) 4. Indexes / partition filters to respect if obvious from {{schema}} If the schema cannot answer the question, do not guess columns - list what is missing.
Negative prompt
Included when you copy the prompt
Do not invent tables or columns missing from {{schema}}. Do not use SELECT *. Do not hide grain or join fan-out risk. Do not write dialect-specific functions that conflict with {{dialect}}. Do not skip the sanity-check query. If the schema cannot answer the question, do not guess - list what is missing and stop.
Fill in your details below - this prompt updates as you type, then copy it.
Fill in your details
0 of 5 filled. Preview updates as you type - then copy the finished prompt (negative prompt included when present).
sql-query-from-a-plain-english-ask.md
Prompt preview
Write SQL for this question. State grain and join assumptions. Question: {{question}} Warehouse / dialect: {{dialect}} Tables I have (names + key columns): {{schema}} Filters: {{filters}} Need: {{need}} Return: 1. Assumptions (grain, time zone, inclusive dates) 2. The query, readable CTEs, no SELECT * 3. How I should sanity-check the result (counts or a duplicate check) 4. Indexes / partition filters to respect if obvious from {{schema}} If the schema cannot answer the question, do not guess columns - list what is missing.
Examples
Example input
Question: Weekly active users who completed at least one order in the same week Warehouse / dialect: BigQuery Standard SQL Tables I have: users(user_id, signup_at, country) events(user_id, event_name, event_at) - event_name includes 'login' orders(order_id, user_id, ordered_at, status) Filters: last 8 complete weeks; country = 'US'; status = 'paid' Need: one row per week with wau_with_order count
What you should get
1. Assumptions: Week = Monday - Sunday UTC; inclusive on ordered_at/event_at; a user counts if they have ≥1 login and ≥1 paid order in the same ISO week; country from users. 2. Query (sketch): WITH weeks AS (...generate last 8 weeks...), logins AS (SELECT user_id, DATE_TRUNC(event_at, WEEK(MONDAY)) AS wk FROM events JOIN users USING(user_id) WHERE event_name='login' AND country='US' AND event_at IN range), buyers AS (SELECT user_id, DATE_TRUNC(ordered_at, WEEK(MONDAY)) AS wk FROM orders JOIN users USING(user_id) WHERE status='paid' AND country='US' AND ordered_at IN range) SELECT wk, COUNT(DISTINCT user_id) AS wau_with_order FROM logins JOIN buyers USING(user_id, wk) GROUP BY 1 ORDER BY 1; 3. Sanity-check: COUNT DISTINCT user_id in logins and buyers separately; check no week has more users than US users who logged in that week; spot-check one user with multiple orders still counts once. 4. Partitions: Filter event_at and ordered_at to the 8-week window first to prune partitions.
When to use this prompt
Use it when
- You need help with analysts.
- You need help with data engineers.
- You need help with pms.
Skip it when
- You only need a one-line ask with no constraints, format, or context.
- You cannot supply the fill-in details the template asks for.
- A different category or tool-specific workflow fits the job better.
How to get a good result
Done when
1. Assumptions: Week = Monday - Sunday UTC; inclusive on ordered_at/event_at; a user counts if they have ≥1 login and ≥1 paid order in the same ISO week; country from users. 2. Query (sketch): WITH weeks AS (...generate last 8 weeks...), logins AS (SELECT user_id, DATE_TRUNC(event_at, WEEK(MONDAY)) AS wk FROM events JOIN users USING(user_id) WHERE event_name='login' AND country='US' AND event_at IN range), buyers AS (SELECT user_id, DATE_TRUNC(ordered_at, WEEK(MONDAY)) AS wk FROM orders JOIN users USING(user_id) WHERE status='paid' AND country='US' AND ordered_at IN range) SELECT wk, COUNT(DISTINCT user_id) AS wau_with_order FROM logins JOIN buyers USING(user_id, wk) GROUP BY 1 ORDER BY 1; 3. Sanity-check: COUNT DISTINCT user_id in logins and buyers separately; check no week has more users than US users who logged in that week; spot-check one user with multiple orders still counts once. 4. Partitions: Filter event_at and ordered_at to the 8-week window first to prune partitions.
Common mistakes
- Leaving question, dialect, schema vague - the model then invents placeholders.
- Asking ChatGPT, Claude, or Gemini for a shorter answer after a long structured prompt - that throws away the format rules.
- Stopping when the first draft appears instead of checking it against the success criteria below.
FAQ
- What do I fill in before I copy this prompt?
- Replace these placeholders with your details: question, dialect, schema, filters, need. Required fields are marked on the page. The prompt text updates as you type.
- Which AI tools is this prompt written for?
- It works best with ChatGPT, Claude, Gemini. Copy the filled prompt and paste it into the tool you already use.
- What should a good result look like?
- 1. Assumptions: Week = Monday - Sunday UTC; inclusive on ordered_at/event_at; a user counts if they have ≥1 login and ≥1 paid order in the same ISO week; country from users. 2. Query (sketch): WITH weeks AS (...generate last 8 weeks...), logins AS (SELECT user_id, DATE_TRUNC(event_at, WEEK(MONDAY)) AS wk FROM events JOIN users USING(user_id) WHERE event_name='login' AND country='US' AND event_at IN range), buyers AS (SELECT user_id, DATE_TRUNC(ordered_at, WEEK(MONDAY)) AS wk FROM orders JOIN …
- What are common mistakes with this prompt?
- Leaving question, dialect, schema vague - the model then invents placeholders. Asking ChatGPT, Claude, or Gemini for a shorter answer after a long structured prompt - that throws away the format rules. Stopping when the first draft appears instead of checking it against the success criteria below.
Best for
- Analysts
- Data engineers
- PMs
Related Prompts
More prompts like this — same topic and style.


