Turn a business question into a SQL query

Describe your tables and the question you need answered and get a correct, commented SQL query with assumptions spelled out.

LLazyPrompt(@lazyprompt)Data & AnalysisGenerateWorks with any model
Prompt template
Write a {{dialect}} query that answers this question.

Question: {{question}}

Schema (tables, columns, types, and how tables join):
{{schema}}

Rules for your answer:
1. Before the query, list your assumptions in bullets: grain of each table, how you interpret ambiguous words in the question (for example "active", "revenue", "last month"), how you handle NULLs, duplicates and time zones.
2. If a missing detail would change the result materially, ask me about it at the end rather than burying a guess, but still give your best-effort query first.
3. Write readable SQL: CTEs with meaningful names, explicit JOIN types with a one-line reason for each, no SELECT *, and comments only where logic is non-obvious.
4. Guard against common errors: join fan-out that multiplies rows, filtering a LEFT JOIN in WHERE, integer division, and counting rows instead of distinct entities.
5. After the query, give a quick validation recipe: 2-3 sanity-check queries or checks to confirm the numbers are right (for example row counts before and after a join, or a total I can compare with a known figure).
6. Mention one way to make it faster if the tables are large.

Output format: Assumptions, Query, What the output columns mean, Validation checks, Questions.
Example output
**Assumptions** - A subscription counts toward a month if it started on or before the month end and was not canceled before the month start (canceled_at IS NULL or later). - MRR uses monthly_price_cents / 100; no discounts or taxes in the schema. - "Last 6 months" = the 6 complete calendar months before the current month. **Query** WITH months AS ( SELECT generate_series(date_trunc('month', CURRENT_DATE) - INTERVAL '6 months', date_trunc('month', CURRENT_DATE) - INTERVAL '1 month', INTERVAL '1 month')::date AS month_start ) SELECT m.month_start, p.name AS plan, COUNT(DISTINCT s.customer_id) AS customers, SUM(s.monthly_price_cents) / 100.0 AS mrr FROM months m JOIN subscriptions s -- inner: months with no subs simply drop out ON s.started_at < m.month_start + INTERVAL '1 month' AND (s.canceled_at IS NULL OR s.canceled_at >= m.month_start) JOIN plans p ON p.id = s.plan_id GROUP BY 1, 2 ORDER BY 1, 2; **Validation** - Compare SUM(mrr) for the latest month with your billing system. - Check COUNT(*) of subscriptions per month is smooth; jumps suggest bad dates. **Questions**: Do paused subscriptions have status = 'paused' and should they count?

Why it works

Stating assumptions and validation checks catches the silent errors that make SQL answers look right but be wrong. Include sample values for status columns to remove guesswork.

Licensed CC0 (public domain) Version 1 · history