Window functions perform calculations across a set of rows related to the current row — without collapsing those rows into a single output row the way GROUP BY aggregates do. They were standardised in SQL:2003 and are now supported by every major analytical database. The defining feature is the OVER() clause: it specifies the window — the partition and ordering — over which the function operates. Window functions let you compute running totals, rankings, moving averages, and lead/lag comparisons while keeping every individual row in the result set visible alongside its computed value.
Before window functions, analysts computed rankings and running totals using correlated subqueries — an approach that scales catastrophically with data volume. Computing the rank of each player in a 10-million-row delivery table required a subquery that re-scanned the table for every row, turning a linear-time problem into a quadratic one. Window functions replace these correlated subqueries with a single linear pass over the partitioned, sorted data, making analytical queries that were previously impractical on large tables routine.
For data engineers, window functions are indispensable in transformation layers. Deduplication (ROW_NUMBER to keep the latest record per entity), session analysis (detecting gaps between events), time-series interpolation (filling missing values from the previous non-null row), and slowly changing dimension (SCD) logic all depend on window functions. Mastering the PARTITION BY and ORDER BY clauses of the OVER() specification is the primary skill required to use window functions correctly and efficiently.