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

> 각 요소의 가중치를 반영하여 숫자 데이터 시퀀스의 분위수를 정확하게 계산합니다.

# quantileExactWeighted

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

도입 버전: v1.1.0

각 요소의 가중치를 고려하여 숫자 데이터 시퀀스의 [분위수](https://en.wikipedia.org/wiki/Quantile)를 정확하게 계산합니다.

정확한 값을 구하기 위해 전달된 모든 값은 하나의 배열로 합쳐진 다음 부분 정렬됩니다.
각 값은 해당 값이 `weight`번 존재하는 것처럼 가중치를 반영하여 계산됩니다.
알고리즘에는 해시 테이블이 사용됩니다.
따라서 전달된 값이 자주 반복되면 이 함수는 [`quantileExact`](/ko/reference/functions/aggregate-functions/quantileExact#quantileExact)보다 RAM을 더 적게 사용합니다.
이 함수는 `quantileExact` 대신 사용할 수 있으며, 가중치로 1을 지정하면 됩니다.

하나의 쿼리에서 수준이 서로 다른 여러 `quantile*` 함수를 사용하면 내부 상태가 결합되지 않습니다(즉, 쿼리가 가능한 수준보다 비효율적으로 동작합니다).
이 경우 [quantiles](/ko/reference/functions/aggregate-functions/quantiles#quantiles) 함수를 사용하십시오.

**구문**

```sql theme={null}
quantileExactWeighted(level)(expr, weight)
```

**별칭**: `medianExactWeighted`

**매개변수**

* `level` — 선택 사항입니다. 분위수 수준입니다. 0에서 1 사이의 상수 부동소수점 수입니다. `level` 값은 `[0.01, 0.99]` 범위에서 사용하는 것을 권장합니다. 기본값은 0.5입니다. `level=0.5`이면 함수가 중앙값을 계산합니다. [`Float*`](/ko/reference/data-types/float)

**인수**

* `expr` — 컬럼 값에 대한 표현식으로, 결과는 숫자 데이터 타입, Date 또는 DateTime이어야 합니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float) 또는 [`Decimal*`](/ko/reference/data-types/decimal) 또는 [`Date`](/ko/reference/data-types/date) 또는 [`DateTime`](/ko/reference/data-types/datetime)
* `weight` — 시퀀스 구성원의 가중치를 담은 컬럼입니다. 가중치는 값의 발생 횟수를 의미합니다. [`UInt*`](/ko/reference/data-types/int-uint)

**반환 값**

지정된 수준의 분위수입니다. [`Float64`](/ko/reference/data-types/float) 또는 [`Date`](/ko/reference/data-types/date) 또는 [`DateTime`](/ko/reference/data-types/datetime)

**예시**

**정확한 가중 분위수 계산**

```sql title=Query theme={null}
CREATE TABLE t (
    n Int32,
    val Int32
) ENGINE = Memory;

-- 샘플 데이터 삽입
INSERT INTO t VALUES
(0, 3),
(1, 2),
(2, 1),
(5, 4);

SELECT quantileExactWeighted(n, val) FROM t;
```

```response title=Response theme={null}
┌─quantileExactWeighted(n, val)─┐
│                             1 │
└───────────────────────────────┘
```

**관련 항목**

* [median](/ko/reference/functions/aggregate-functions/median)
* [quantiles](/ko/reference/functions/aggregate-functions/quantiles)
