Keep Ranking and Window Choices at Your Fingertips
Recall which ranking or window pattern matches a common analytical request without re-deriving it from scratch.
Which ranking function matches the request? Tie behavior is the real choice. Choose by tie semantics first, not by familiarity. When do you reach for lag()? When the current row needs a value from the previous row in the same ordered partition. Examples include session-gap detection, change tracking, and period-over-period comparisons. I can just GROUP BY and join the summary back later. Better move Use a window when the final output still needs the detailed rows, because grouping early throws away grain you may later duplicate or misjoin. Aggregate-then-join often reintroduces tie and duplication bugs that the window would have…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in