> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> `any` のエイリアスですが、[Window Functions](/reference/functions/window-functions) との互換性のために導入されました。Window Functions では `NULL` 値を処理する必要がある場合があり（デフォルトでは ClickHouse のすべての集約関数は NULL 値を無視します）。

# first_value

[`any`](/ja/reference/functions/aggregate-functions/any) のエイリアスですが、[Window Functions](/ja/reference/functions/window-functions) との互換性のために導入されました。Window Functions では `NULL` 値を処理する必要がある場合があり (デフォルトでは ClickHouse のすべての集約関数は NULL 値を無視します) 。

[Window Functions](/ja/reference/functions/window-functions) と通常の集計の両方で、NULL を考慮する修飾子 (`RESPECT NULLS`) を指定できます。

`any` と同様に、Window Functions を使用しない場合、入力ストリームが順序付けされていなければ結果はランダムになり、戻り値の型は入力型と一致します
(`NULL` が返されるのは、入力が Nullable であるか、-OrNull combinator が追加されている場合のみです) 。

<div id="examples">
  ## 例
</div>

```sql theme={null}
CREATE TABLE test_data
(
    a Int64,
    b Nullable(Int64)
)
ENGINE = Memory;

INSERT INTO test_data (a, b) VALUES (1,null), (2,3), (4, 5), (6,null);
```

<div id="example1">
  ### 例 1
</div>

デフォルトでは、NULL 値は無視されます。

```sql theme={null}
SELECT first_value(b) FROM test_data;
```

```text theme={null}
┌─any(b)─┐
│      3 │
└────────┘
```

<div id="example2">
  ### 例 2
</div>

NULL 値は無視されます。

```sql theme={null}
SELECT first_value(b) ignore nulls FROM test_data
```

```text theme={null}
┌─any(b) IGNORE NULLS ─┐
│                    3 │
└──────────────────────┘
```

<div id="example3">
  ### 例 3
</div>

NULL 値を使用できます。

```sql theme={null}
SELECT first_value(b) respect nulls FROM test_data
```

```text theme={null}
┌─any(b) RESPECT NULLS ─┐
│                  ᴺᵁᴸᴸ │
└───────────────────────┘
```

<div id="example4">
  ### 例 4
</div>

`ORDER BY` を使用したサブクエリによる結果の安定化。

```sql theme={null}
SELECT
    first_value_respect_nulls(b),
    first_value(b)
FROM
(
    SELECT *
    FROM test_data
    ORDER BY a ASC
)
```

```text theme={null}
┌─any_respect_nulls(b)─┬─any(b)─┐
│                 ᴺᵁᴸᴸ │      3 │
└──────────────────────┴────────┘
```
