SQL Window Functions: OVER Clause, PARTITION BY, ORDER BY, and Frames/Use RANGE for peer-aware frames
Group rows that share the same ordering value.
Section: OVER clause fundamentals
Use RANGE for peer-aware frames
sql
sql
SELECT score,
COUNT(*) OVER (
ORDER BY score
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
) AS cumulative_count
FROM exam_results;Explanation
`RANGE` can treat rows with equal sort values as peers, which often changes cumulative results compared with `ROWS`.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing OVER clause fundamentals
Count all rows without collapsing them
Return total row count on every row.
Assign row numbers inside each partition
Number rows in order within each customer.
Exclude the current row from a frame
Compare a row against all earlier rows only.