Break the query into its logical clauses (FROM/JOIN, WHERE, GROUP BY, HAVING, SELECT, window functions, ORDER BY) and trace the data step by step. For each step, describe how rows are filtered, combined, grouped, or transformed, and how NULLs and duplicates are handled. Finally, summarize the exact result set: columns, row values, and ordering.
Pro tip: Mention that window functions are evaluated after WHERE, GROUP BY, and HAVING but before ORDER BY, and that they do not collapse rows like GROUP BY does. Also note that NULLs are treated as equal in GROUP BY and DISTINCT but not in comparisons, and that duplicate rows are preserved unless DISTINCT or GROUP BY is used.
Identify the order of evaluation: FROM/JOIN, WHERE, GROUP BY, HAVING, SELECT, window functions, ORDER BY, LIMIT. This determines how data flows and transforms.
Determine how tables are combined (INNER, LEFT, etc.) and which rows are removed by WHERE. Explain how NULLs from outer joins affect subsequent steps.
For GROUP BY, describe how rows collapse into groups and how NULLs are grouped. For window functions, explain partitioning, ordering, and framing, and how they compute values without collapsing rows.
List the output columns and their values after all transformations. Specify the final ordering, including how NULLs are sorted (e.g., NULLS FIRST/LAST) and tie-breaking.
State exactly which rows are returned, what each column contains, and how duplicates and NULLs are handled in the final output.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.