The OVER () clause defines the window frame , i.e., which rows are considered for the calculation.
Traditional aggregate functions that analyze the entire result set, window functions are a specialized category that zooms in on a defined window of rows.
This window functions as a dynamic boundary, enabling calculations on a specific subset of rows linked to the current row.
Analogy: Like placing a spotlight on one group at a time — each group has its own focus.
ORDER BY: This clause within OVER() defines the order in which the rows in a partition (or the entire result set, if no PARTITION BY is specified) are processed by the window function. This is crucial for functions where the order of rows is significant, such as running totals or cumulative averages.
Frame Specification (ROWS/RANGE): In addition to PARTITION BY and ORDER BY, you can further refine the window frame by specifying which rows around the current row should be included in the frame.
