> ## 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`의 별칭이지만, [윈도우 함수]와의 호환성을 위해 도입되었습니다. 윈도우 함수에서는 때때로 `NULL` 값을 처리해야 하기 때문입니다(기본적으로 모든 ClickHouse 집계 함수는 `NULL` 값을 무시합니다).

# first_value

[`any`](/ko/reference/functions/aggregate-functions/any)의 별칭이지만, [윈도우 함수](/ko/reference/functions/window-functions)와의 호환성을 위해 도입되었습니다. 윈도우 함수에서는 때때로 `NULL` 값을 처리해야 하기 때문입니다(기본적으로 모든 ClickHouse 집계 함수는 `NULL` 값을 무시합니다).

[윈도우 함수](/ko/reference/functions/window-functions)와 일반 집계 모두에서 `NULL`을 유지하는 수정자(`RESPECT NULLS`) 선언을 지원합니다.

`any`와 마찬가지로, 윈도우 함수 없이 사용하면 입력 스트림이 정렬되어 있지 않을 경우 결과는 임의적이며 반환 유형은 입력 유형과 일치합니다
(입력이 널 허용이거나 `-OrNull` combinator가 추가된 경우에만 `Null`이 반환됩니다).

<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 │
└──────────────────────┴────────┘
```
