Window functions perform calculations across a set of rows related to the current row, without collapsing them into a single output row like aggregates do. Syntax Common Window Functions Function Purpose ROWNUMBER() Unique sequential number per partition RANK() Rank with gaps for ties DENSERANK() Rank without gaps NTILE(n) Divide rows into n equal buckets LAG(col, n) Value from n rows before LEAD(col, n) Value from n rows after FIRSTVALUE(col) First value in the window frame LASTVALUE(col) Last value in the window frame SUM/AVG/COUNT OVER() Running or partitioned aggregates Frame Specification The frame defines which rows are included in the window: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW — cumulative ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING — sliding 3-row window RANGE BETWEEN…