Reference material for FIRST_VALUE function
Parameter | Description | Supported input types |
---|---|---|
<expression> | A SQL expression of any type to evaluate. | Any |
<partition_by> | An expression used for the PARTITION BY clause. | Any |
<order_by> | An expression used for the order by clause. | Any |
<expression>
.
This function respects NULL
values, and the results will be ordered with the default NULL
ordering NULLS LAST
unless
otherwise specified in the ORDER BY
clause. If no ORDER BY
clause is applied, the order will be undefined.
nickname
, level
, current_score
, and highest_score
for each level, using the NTH_VALUE
function to retrieve the top score within each level, ordered by current_score
in descending order.
Example
The following query uses UNNEST
to convert an array [1,2,5]
into a column, order the values, and returns the first value as result
:
result (INTEGER) |
---|
1 |
1 |
1 |
UNNEST
to convert an array [100, NULL, 1]
into a column, order the values, and returns the first value as result
:
result (INTEGER) |
---|
NULL |
NULL |
NULL |
NULL
values because ORDER BY
specifies ‘nulls first’.