ClickHouse/docs/en/sql-reference/aggregate-functions/reference/first_value.md
2023-05-30 10:09:12 +08:00

1.1 KiB

slug sidebar_position
/en/sql-reference/aggregate-functions/reference/first_value 7

first_value

Selects the first encountered value, similar to any, but could accept NULL.

examples

insert into test_data (a,b) values (1,null), (2,3), (4, 5), (6,null)

example1

The NULL value is ignored at default.

select first_value(b) from test_data
┌─first_value_ignore_nulls(b)─┐
│                           3 │
└─────────────────────────────┘

example2

The NULL value is ignored.

select first_value(b) ignore nulls from test_data
┌─first_value_ignore_nulls(b)─┐
│                           3 │
└─────────────────────────────┘

example3

The NULL value is accepted.

select first_value(b) respect nulls from test_data

┌─first_value_respect_nulls(b)─┐
│                         ᴺᵁᴸᴸ │
└──────────────────────────────┘