Training
Module
Write queries that use window functions - Training
This content is a part of Write queries that use window functions.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
first_value
aggregate functionApplies to: Databricks SQL
Databricks Runtime
Returns the first value of expr
for a group of rows. This function is a synonym for first
aggregate function.
first_value(expr[, ignoreNull]) [FILTER ( WHERE cond ) ]
This function can also be invoked as a window function using the OVER
clause.
expr
: An expression of any type.ignoreNull
: An optional BOOLEAN
literal that defaults to false.cond
: An optional boolean expression filtering the rows used for aggregation.IGNORE NULLS
or RESPECT NULLS
: When IGNORE NULLS
is used or ignoreNull
is true
any expr
value that is NULL is ignored. The default is RESPECT NULLS
.The result has the same type as expr
.
This function is non-deterministic.
> SELECT first_value(col) FROM VALUES (10), (5), (20) AS tab(col);
10
> SELECT first_value(col) FROM VALUES (NULL), (5), (20) AS tab(col);
NULL
> SELECT first_value(col, true) FROM VALUES (NULL), (5), (20) AS tab(col);
5
> SELECT first_value(col) IGNORE NULLS FROM VALUES (10), (5), (NULL) AS tab(col);
5
> SELECT first_value(col) FILTER (WHERE col > 5) FROM VALUES (5), (20) AS tab(col);
20
Training
Module
Write queries that use window functions - Training
This content is a part of Write queries that use window functions.