Description
Returns the relative rank of a value within a partition (0 to 1).
Syntax
PERCENT_RANK()
OVER (
[PARTITION BY partition_expression]
ORDER BY sort_expression [ASC|DESC]
)
Parameters
| Parameter | Description | Data Type | Required |
|---|---|---|---|
| PARTITION BY | Divides the result set into groups before applying the window function | Clause | No |
| ORDER BY | Defines how rows are ordered within the partition | Clause | Yes |
Rewrite
Use QUALIFY to filter on window expression results; do not use window functions in WHERE.
Notes
- Include an
OVER (...)clause withORDER BY(and optionalPARTITION BY) when using this as a window function.
Example
SELECT
id, PERCENT_RANK() OVER (PARTITION BY department ORDER BY start_date) AS pr
FROM
rippling.employee.Employee;