Syntax
Parameters
| Parameter | Description | Supported input types |
|---|---|---|
<expression> | A SQL expression of any type to evaluate. | Any |
<n> | A constant integer in range [1, max of datatype INTEGER] to indicate the row number to evaluate. | INTEGER |
<partition_by> | An expression used for the PARTITION clause. | Any |
<order_by> | An expression used for the order by clause. | Any |
Return Types
Same as input type. This function respectsNULL values, and results will be ordered with default null ordering NULLS LAST unless otherwise specified in the ORDER BY clause. If applied without an ORDER BY clause, the order will be undefined.
Example
The example below returns the student with the second highest test score for each grade level. Notice that the function returnsNULL for the first row in each partition, unless the value of the expression for first and second rows of the partition are equal.
| nickname | level | current_score | second_highest_score |
|---|---|---|---|
| ymatthews | 9 | 85 | Sammy |
| rileyjon | 10 | 89 | null |
| kennethpark | 11 | 94 | null |
| sabrina21 | 12 | 100 | burchdenise |