SQL · CHEAT SHEET

SQL Window Functions Cheat Sheet

ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD and running totals with practical patterns.

FilterWHERE Status = 'Open'
PatternWHERE Code LIKE 'AK%'
GroupGROUP BY Material
Post-filterHAVING COUNT(*) > 1
Missing matchLEFT JOIN ... WHERE right.Key IS NULL
Latest rowROW_NUMBER() OVER(PARTITION BY Key ORDER BY Time DESC)

Use the pattern, then verify the result

Cheat sheets are reminders, not substitutes for checking keys, data types, duplicates and edge cases. Follow the linked learning material when a pattern is new to you.