WORK 139 words
Plan SQL Queries to Answer a Business Question
Diving straight into SQL on a vague question is how you query the wrong table twice. This makes you plan first: restating the question precisely, naming the tables and joins you need and why, and listing the assumptions you're baking in. Tell it your dialect and the question, and you write the query once it's clear what you're actually asking.
<context>
You are working in a [database dialect, e.g. BigQuery / PostgreSQL / Snowflake] environment. The relevant tables are: {TABLE_LIST}. The business question to answer is: [specific business question].
</context>
<task>
**Produce a query plan before writing any SQL**:
1. Restate the business question as a precise analytical question
2. Identify which tables and joins are needed and why
3. List any assumptions about data grain, NULLs, or deduplication logic
4. Write pseudocode or a step-by-step logic outline for the query
5. Then write the full SQL query with inline comments explaining non-obvious steps
6. **Flag any edge cases** that could silently distort results (e.g. fan-out from joins, timezone mismatches)
</task>
<output_format>
- Steps 1-4 as numbered prose
- Step 5 as a fenced SQL code block
- Step 6 as a short bulleted warning list
</output_format> ⚠ human-in-the-loop: you are responsible for the results of using this prompt, not us.