Skip to main content
ReferenceApplies to: Unified engine deployments
Window functions compute values over related rows while retaining a result row for each input row. The OVER clause defines the partition, ordering, and optional frame.

Syntax

PARTITION BY restarts the calculation for each key. With no PARTITION BY, all rows belong to one partition. A window ORDER BY determines calculation order, while the query’s final ORDER BY determines result presentation.

Ranking

ROW_NUMBER assigns a unique sequence. RANK leaves gaps after ties; DENSE_RANK does not. Include a unique ordering key when a deterministic row sequence matters.

Explicit frames

ROWS counts physical rows. RANGE groups rows by ordering values, so peers can affect the result. A frame can use UNBOUNDED PRECEDING, a supported offset PRECEDING or FOLLOWING, CURRENT ROW, and UNBOUNDED FOLLOWING. Be explicit for cumulative or whole-partition calculations.

Previous and next values

LAG and LEAD read values at an offset within a partition. Their default offset is one. A value outside the partition is NULL unless a default is supplied.
Filter a window result using an outer query; see CTEs and subqueries. Explicit IGNORE NULLS or RESPECT NULLS treatment is rejected by Native execution when it cannot preserve that behavior. See window functions for additional signatures.
Last modified on November 4, 2026