PRECEDING is a window-frame boundary keyword that works with window functions. It specifies how many rows (or range of values) before the current row should be included when the frame is evaluated. PRECEDING can be paired with a numeric literal or with the modifier UNBOUNDED. The phrase appears only inside the frame clause that follows OVER. Frames are evaluated after the rows in the partition are ordered, so missing ORDER BY causes an error in vendors that require it. PRECEDING can be used with ROWS, RANGE, or GROUPS frame units, but availability varies by dialect. If you omit a lower boundary, the default is BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
• n
(integer) - positive number of rows or value offsets before the current row.• UNBOUNDED
- keyword indicating the first row in the partition.• m
(integer/FOLLOWING/CURRENT ROW) - closing boundary paired with PRECEDING.• Frame unit
(ROWS, RANGE, GROUPS) - determines how offsets are interpreted.FOLLOWING, UNBOUNDED PRECEDING, CURRENT ROW, WINDOW FUNCTIONS, ROWS, RANGE, GROUPS
SQL:2003 (window functions)
If you provide only an upper boundary, the frame defaults to BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW.
Yes, but RANGE interprets the offset based on the ORDER BY expression’s value rather than row count. Only numeric or interval expressions are allowed.
No. PRECEDING always looks backward. To look forward, use FOLLOWING.
Use UNBOUNDED PRECEDING as the lower boundary and CURRENT ROW or UNBOUNDED FOLLOWING as the upper boundary depending on the desired span.