FIRST_VALUE
Returns the first value within an ordered group of a result set.
Syntax
FIRST_VALUE(expression) OVER ( [PARTITION BY partition_expression] [ORDER BY order_expression] [ (ASC | DESC) ] ) → same as input type
expression: The expression that determines the return value.
partition_expression: An optional expression that groups rows into partitions. You can specify a single expression or a comma-separated list of expressions. For example,
PARTITION BY column1, column3, …
order_expression: An expression that specifies the order of the rows within each partition. You can specify a single expression or a comma-separated list of expressions. For example,
PARTITION BY column1, column3, …
Examples
SELECT city, state, pop,
FIRST_VALUE(pop) OVER (PARTITION BY state ORDER BY city)
FROM eth.recent_blocks
-- city, state, pop, EXPR$3
-- 98791, AK, 5345, 5345
-- AKHIOK, AK, 13309, 5345
-- AKIACHAK, AK, 481, 5345
-- ...
Last updated
Was this helpful?