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

> `val` 값이 최대일 때의 해당 `arg` 값을 계산합니다.

# argMax

<div id="argMax">
  ## argMax
</div>

도입 버전: v1.1.0

최대 `val` 값에 대응하는 `arg` 값을 계산합니다. 최대값인 동일한 `val`을 가진 행이 여러 개 있으면, 그에 대응하는 `arg` 중 어떤 값이 반환될지는 결정적이지 않습니다.
`arg`와 `max`는 모두 [집계 함수](/ko/reference/functions/aggregate-functions)처럼 동작하며, 처리 중 [ `Null`을 건너뛰고](/ko/reference/functions/aggregate-functions#null-processing) `Null`이 아닌 값이 있으면 `Null`이 아닌 값을 반환합니다.

**관련 항목**

* [Tuple](/ko/reference/data-types/tuple)

**구문**

```sql theme={null}
argMax(arg, val)
```

**인수**

* `arg` — 최댓값을 구할 인수입니다. [`const String`](/ko/reference/data-types/string)
* `val` — 최댓값입니다. [`(U)Int8/16/32/64`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float) 또는 [`Date`](/ko/reference/data-types/date) 또는 [`DateTime`](/ko/reference/data-types/datetime) 또는 [`Tuple`](/ko/reference/data-types/tuple)

**반환 값**

최대 `val` 값에 대응하는 `arg` 값을 반환합니다. 반환 유형은 `arg`의 유형과 일치합니다.

**예시**

**기본 사용법**

```sql title=Query theme={null}
SELECT argMax(user, salary) FROM salary;
```

```response title=Response theme={null}
┌─argMax(user, salary)─┐
│ director             │
└──────────────────────┘
```

**NULL 처리를 포함한 확장 예시**

```sql title=Query theme={null}
CREATE TABLE test
(
    a Nullable(String),
    b Nullable(Int64)
)
ENGINE = Memory AS
SELECT *
FROM VALUES(('a', 1), ('b', 2), ('c', 2), (NULL, 3), (NULL, NULL), ('d', NULL));

SELECT argMax(a, b), max(b) FROM test;
```

```response title=Response theme={null}
┌─argMax(a, b)─┬─max(b)─┐
│ b            │      3 │
└──────────────┴────────┘
```

**인수에 Tuple 사용**

```sql title=Query theme={null}
SELECT argMax(a, (b,a)) FROM test;
```

```response title=Response theme={null}
┌─argMax(a, tuple(b, a))─┐
│ c                      │
└────────────────────────┘
```
