Skip to content

About: SQL Window Functions Cheatsheet

← Back to deck

223 cards

Overview

This deck is a focused walkthrough of SQL window functions, the set of features that let you compute values across rows related to the current one without collapsing them into a single output row. The cards walk through the most common patterns you'll reach for in real querying: running totals, rankings within groups, lag and lead lookups, moving averages, percentile ranks, and bucketing rows into N equal slices. You'll also untangle the subtle gotchas, like why a plain LAST_VALUE can quietly return the wrong answer and how a frame clause fixes it.

It's a good fit if you're an analyst, data engineer, or anyone writing SQL beyond basic SELECT and GROUP BY queries, and especially useful if you're preparing for a technical interview where window functions come up frequently. The concepts here tend to trip people up because window functions look like ordinary aggregates but behave differently: they keep row-level detail while still letting you compare across partitions. Working through the differences between ROW_NUMBER, RANK, and DENSE_RANK, or between a window aggregate and a grouped aggregate, will sharpen that intuition.

Because the cards are phrased as questions, try answering each one out loud or sketching the syntax on paper before flipping. When a card asks for a query, actually run it in a SQL playground if you can — muscle memory for the OVER (...) clause is worth more than rereading the answer. The topics build on each other, so if a later card about FIRST_VALUE or moving averages feels shaky, it's worth revisiting the earlier partitioning and ordering cards first. Spacing your review over a few days rather than cramming will help the patterns stick, since window function syntax rewards steady, repeated exposure more than a single long session.