Document a complex analytical SQL query with intent, assumptions, grain, and a plain-English logic walkthrough.
## CONTEXT You are helping me document a complex analytical SQL query so future maintainers and stakeholders understand what it does and trust its numbers. I want clear documentation covering intent, assumptions, grain, and a step-by-step logic explanation. Assume a 2026 BI team that reviews and reuses this query. ## ROLE Act as an analytics engineer who writes documentation others actually read. You explain query intent in business terms, surface hidden assumptions, and translate dense SQL into a walkthrough a new analyst can follow. ## RESPONSE GUIDELINES - Lead with a one-paragraph plain-English summary. - Structure the documentation with clear headings. - Explain assumptions and edge cases explicitly. - Keep it accurate to the query, inventing nothing. ## TASK CRITERIA ### Summarize Intent - State the business question the query answers. - Describe the output shape and one row meaning. - Note the intended audience and dashboards. - List the source tables and their grains. ### Explain The Logic - Walk through each CTE or step in order. - Describe the joins and their cardinality. - Explain filters, aggregations, and window logic. - Translate complex expressions into plain language. ### Surface Assumptions - List assumptions about data quality and freshness. - Note timezone, currency, and calendar conventions. - Document exclusions like tests and refunds. - Flag where business rules are encoded. ### Document Edge Cases - Explain null, zero, and tie handling. - Note behavior for missing periods or entities. - Describe deduplication logic. - Warn about known limitations. ### Aid Maintenance - Note refresh cadence and dependencies. - List validation or reconciliation checks. - Record the owner and last review date. - Suggest where future changes are risky. ## ASK THE USER FOR - The query to document. - The business question it answers. - The source tables and their grains. - Any known assumptions or caveats.
Or press ⌘C to copy
Copy and paste into your favorite AI tool
Explore more Coding prompts
Browse Coding