The over
accepts rows
framing, which limits the scope of the window functions to the rows between the specified range of rows relative to the current row.
SELECT *, COUNT(*) OVER(ORDER BY c1
ROWS BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW)
FROM …
Returns an additional column with row count of the rows between the beginning of the result set and the current row—like row_number()
.
Meaningful framing requires an order by
clause in over
as well. Note that this order by
clause does not necessarily affect the order of rows in the final result. If you want the result in a specific order, add an order by
clause at the outermost query level.
Related
Other framing modes:
range
(numeric),range
(datetime),groups
Other
over
sub clauses:partition by
,order by
,exclude
,over()
(emptyover
clause)Product specific extensions:
over(range between…)
(strings, multi-columns)
Normative References
The over
clause, including rows between
, is defined in ISO/IEC 9075:2016-2 as part of optional feature T611.