ThinkWithPrompt by SynotticThinkWithPrompt

Write a SQL query from plain English

Turns a business question into SQL, with validation checks and an explanation.

Data & AnalysisRCTFVVAdvancedData & AnalyticsWriteAnalyzeFill-in Template

The prompt

Role: Act as a data analyst writing and validating SQL for a business question. Context: The business question: [QUESTION]. Schema (tables, key columns, types, relationships, grain): [SCHEMA]. Metric and dimension definitions that apply: [DEFINITIONS]. Known data quirks (soft deletes, timezones, late-arriving data, duplicates): [QUIRKS]. SQL dialect: [DIALECT]. Row-count or spot-check figures I can compare against: [KNOWN_FIGURES]. Goal: Return a query that answers exactly the question asked, with the interpretation and assumptions explicit and a way to confirm the result is right. Task: Produce: (1) a restatement of the question in precise terms, listing every interpretation choice (time grain, filters, how the metric is defined, how nulls and duplicates are handled); (2) the SQL, readable, with comments on the non-obvious parts; (3) validation steps - checks to run (row counts, totals, a spot-check against a known figure, an edge-case filter) and what each would reveal if wrong; (4) common ways this query could be subtly wrong and how you guarded against them. Constraints: Use only tables/columns in the provided schema - do not assume columns exist. Handle the stated quirks explicitly. If the question is ambiguous, pick the most likely interpretation, state it, and note the alternative. Show the assumptions, do not bury them. Examples: Interpretation note: '"Active users last month" = distinct user_id with >=1 event where event_date in the previous full calendar month, excluding is_internal=true and soft-deleted users (deleted_at is null).' Format: Sections: Question restated + interpretation choices | SQL (commented) | Validation steps | Subtle-error risks & guards. Verification: For each interpretation choice, say why it is the most defensible reading; flag any part of the question the schema cannot answer. Validation: Run the validation steps mentally against the known figures: does the result reconcile? If a check would fail, fix the query and say what was wrong.

Highlighted [brackets] are blanks to replace with your own details.

Fill in the blanks and use this promptMore Data & Analysis prompts

What to fill in

  • QUESTION
  • SCHEMA
  • DEFINITIONS
  • QUIRKS
  • DIALECT
  • KNOWN_FIGURES

How this prompt is built

This prompt follows the RCTFVV structure (Role, Context, Task, Format, Verification, Validation). RCTFVV extends RCTF with two checking steps. Verification asks the model to review its own draft against your requirements; Validation asks it to flag assumptions and gaps you should confirm.

Related prompts

Find more prompts like this