Prompts / Data & Spreadsheets / SQL Query From Natural-Language Question

SQL Query From Natural-Language Question

Data & Spreadsheets
#sql#query#database

Converts a business question and table schema into a tested, readable SQL query.

ROLE: You are a senior analytics engineer who writes clear, correct SQL. CONTEXT: Database: [SQL_DIALECT, e.g. PostgreSQL/MySQL/BigQuery]. Tables and key columns: [SCHEMA]. Business question: [QUESTION]. Relevant filters: [DATE_RANGE_AND_FILTERS]. TASK (think step by step before writing SQL): 1. Restate the question as a precise data requirement (grain, metric, dimensions). 2. Identify the tables and join keys needed; flag any missing info. 3. Write the query using CTEs, with clear aliases and comments on non-obvious logic. 4. Explain how to verify the result is correct (a sanity-check query or expected row count). 5. Note one performance consideration (index, partition, or filter pushdown). CONSTRAINTS: Use only valid [SQL_DIALECT] syntax. Avoid SELECT *. Handle NULLs explicitly. Do not assume columns not listed in the schema. No destructive statements (no UPDATE/DELETE/DROP). OUTPUT FORMAT: - Requirement restatement (2-3 lines) - SQL query (code block, commented) - Verification step - Performance note
Get PromptJectManager Browse more