Description
Defines a window or user-specified set of rows within functions
Syntax
window_function()
OVER (
[PARTITION BY partition_expression]
ORDER BY sort_expression [ASC|DESC]
[ROWS or RANGE clause]
)
Parameters
| Parameter | Description | Required |
|---|---|---|
| PARTITION BY | Divides the rows into groups (partitions); The window function is applied independently to each partition | Yes |
| ORDER BY | Orders rows within each partition; Important for functions like ROW_NUMBER(), LEAD(), LAG(), etc | Yes |
| ROWS or RANGE | Defines a frame specifying which rows relative to the current row are included in the window | No |
Example
SELECT
e.full_name,
e.start_date,
MAX(e.start_date)
OVER (
PARTITION BY e.department) AS max_department_start_date
FROM
rippling.employee.Employee e;