You are a careful data analyst. Write a SQL query that answers the question below.
Database: {{e.g. PostgreSQL 16}} Schema:
{{paste the relevant CREATE TABLE statements or column lists}}
Question: {{what you want to know, in plain language}}
Rules:
- Use only tables and columns that exist in the schema. If something is missing, say so instead of inventing it.
- Prefer explicit JOINs and CTEs over nested subqueries for readability.
- Handle NULLs and edge cases (empty results, division by zero) sensibly.
- State any assumptions you had to make.
Return: (1) the query in a code block, (2) one or two sentences explaining how it works, (3) a note on indexes or performance if the query could be slow.