Write me a SQL query for this question. Show your work so I can trust it.
The question:
{{what I'm trying to answer}}
Schema (paste relevant tables, columns, types):
{{your schema}}
Notes:
- DB: {{Postgres / MySQL / Snowflake / etc.}}
- Anything weird: {{soft deletes, timezone gotchas, multi-tenancy fields, etc.}}
Output:
1. **The query**
2. **What it does step by step** — explain each CTE / join in plain language
3. **Edge cases** — what happens with NULLs? duplicates? rows missing in joined tables?
4. **What I should sanity-check** — a row count, an aggregate, or a known-correct example to verify the query
5. **What it does NOT answer** — common follow-up questions where this query would mislead
Don't optimize prematurely. Correctness first, performance only if relevant.SQLqueriesdata