Description
Specifies rows within a function
Syntax
window_function()
OVER (
[PARTITION BY partition_expression]
ORDER BY sort_expression [ASC | DESC]
ROWS BETWEEN frame_start AND frame_end
)
Parameters
| Parameters | Description | Required |
|---|---|---|
| PARTITION BY | Divides rows into groups before numbering restarts in each group | No |
| ORDER BY | Defines the order in which row numbers are assigned | Yes |
Common ROWS frame options
| Frame Option | Meaning |
|---|---|
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW | From the first row in the partition to the current row |
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING | From the current row to the last row |
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING | One row before and one row after |
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING | Entire partition |
Example
SELECT
MIN(e.start_date) OVER (
PARTITION BY e.department
ORDER BY e.id
ROWS BETWEEN UNBOUNDED PRECEDING
AND UNBOUNDED FOLLOWING
) AS dates
FROM
rippling.employee.Employee e;