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

> 산술 함수 문서

# 산술 함수

<h2 id="overview">
  개요
</h2>

산술 함수는 `UInt8`, `UInt16`, `UInt32`, `UInt64`, `Int8`, `Int16`, `Int32`, `Int64`, `Float32` 또는 `Float64` 타입의 임의의 두 피연산자에 대해 동작합니다.

연산을 수행하기 전에 두 피연산자는 결과 타입으로 변환됩니다. 결과 타입은 다음과 같이 결정됩니다(아래 함수 문서에서 별도로
지정하지 않는 한).

* 두 피연산자가 모두 32비트 이하이면 결과 타입의 크기는 두 피연산자 중 더 큰 타입보다 한 단계 큰 타입의 크기가 됩니다
  (정수 크기 승격). 예를 들어 `UInt8 + UInt16 = UInt32` 또는 `Float32 * Float32 = Float64`입니다.
* 피연산자 중 하나가 64비트 이상이면 결과 타입의 크기는 두 피연산자 중 더 큰 타입과 동일한 크기가 됩니다. 예를
  들어 `UInt32 + UInt128 = UInt128` 또는 `Float32 * Float64 = Float64`입니다.
* 피연산자 중 하나가 부호 있는 타입이면 결과 타입도 부호 있는 타입이 되고, 그렇지 않으면 부호 없는 타입이 됩니다. 예를 들어 `UInt32 * Int32 = Int64` 또는 `UInt32 * UInt32 = UInt64`입니다.

이 규칙은 결과 타입이 가능한 모든 결과를 표현할 수 있는 가장 작은 타입이 되도록 합니다. 이로 인해 값 범위 경계 부근에서는
오버플로우 위험이 생길 수 있지만, 최대 64비트 네이티브 정수 폭을 사용해 계산을 빠르게 수행할 수 있습니다. 또한 이러한 동작은
64비트 정수(BIGINT)를 가장 큰 정수 타입으로 제공하는 다른 많은 데이터베이스와의 호환성도 보장합니다.

예시:

```sql theme={null}
SELECT toTypeName(0), toTypeName(0 + 0), toTypeName(0 + 0 + 0), toTypeName(0 + 0 + 0 + 0)
```

```text theme={null}
┌─toTypeName(0)─┬─toTypeName(plus(0, 0))─┬─toTypeName(plus(plus(0, 0), 0))─┬─toTypeName(plus(plus(plus(0, 0), 0), 0))─┐
│ UInt8         │ UInt16                 │ UInt32                          │ UInt64                                   │
└───────────────┴────────────────────────┴─────────────────────────────────┴──────────────────────────────────────────┘
```

오버플로우는 C++와 같은 방식으로 발생합니다.

## abs

도입 버전: v1.1.0

`x`의 절대값을 계산합니다. `x`가 부호 없는 유형이면 값에 변화가 없습니다. `x`가 부호 있는 유형이면 부호 없는 숫자를 반환합니다.

**구문**

```sql theme={null}
abs(x)
```

**인수**

* `x` — 절댓값을 구할 대상 값

**반환 값**

`x`의 절댓값

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT abs(-0.5)
```

```response title=Response theme={null}
0.5
```

## avg2

도입 버전: v25.11.0

전달된 인수의 평균값을 계산해 반환합니다.
숫자 및 시간 관련 타입을 지원합니다.

**구문**

```sql theme={null}
avg2(x1, x2])
```

**인수**

* `x1, x2]` — 평균 계산에 사용할 두 값을 받습니다.

**반환 값**

제공된 인수의 평균값을 반환합니다. 결과는 호환 가능한 가장 큰 유형으로 승격됩니다.

**예시**

**숫자 타입**

```sql title=Query theme={null}
SELECT avg2(toUInt8(3), 1.0) AS result, toTypeName(result) AS type;
-- UInt8이 비교를 위해 64비트로 승격되어야 하므로 반환되는 유형은 Float64입니다.
```

```response title=Response theme={null}
┌─result─┬─type────┐
│      2 │ Float64 │
└────────┴─────────┘
```

**Decimal 타입**

```sql title=Query theme={null}
SELECT avg2(toDecimal32(1, 2), 2) AS result, toTypeName(result) AS type;
```

```response title=Response theme={null}
┌─result─┬─type──────────┐
│    1.5 │ Decimal(9, 2) │
└────────┴───────────────┘
```

**날짜 타입**

```sql title=Query theme={null}
SELECT avg2(toDate('2025-01-01'), toDate('2025-01-05')) AS result, toTypeName(result) AS type;
```

```response title=Response theme={null}
┌─────result─┬─type─┐
│ 2025-01-03 │ Date │
└────────────┴──────┘
```

**DateTime 타입**

```sql title=Query theme={null}
SELECT avg2(toDateTime('2025-01-01 00:00:00'), toDateTime('2025-01-03 12:00:00')) AS result, toTypeName(result) AS type;
```

```response title=Response theme={null}
┌──────────────result─┬─type─────┐
│ 2025-01-02 06:00:00 │ DateTime │
└─────────────────────┴──────────┘
```

**Time64 타입**

```sql title=Query theme={null}
SELECT avg2(toTime64('12:00:00', 0), toTime64('14:00:00', 0)) AS result, toTypeName(result) AS type;
```

```response title=Response theme={null}
┌───result─┬─type──────┐
│ 13:00:00 │ Time64(0) │
└──────────┴───────────┘
```

## byteSwap

도입 버전: v23.10.0

정수의 바이트 순서를 뒤집습니다. 즉, [엔디언 방식](https://en.wikipedia.org/wiki/Endianness)을 변경합니다.

아래 예시는 다음과 같은 방식으로 계산할 수 있습니다:

1. 10진수 정수를 big-endian 기준의 16진수 포맷으로 변환합니다. 즉, 3351772109 -> C7 C7 FB CD (4바이트)
2. 바이트 순서를 뒤집습니다. 즉, C7 C7 FB CD -> CD FB C7 C7
3. 결과를 big-endian으로 가정하고 다시 정수로 변환합니다. 즉, CD FB C7 C7 -> 3455829959
   이 함수의 한 가지 사용 예시는 IPv4의 바이트 순서를 뒤집는 것입니다:

```result theme={null}
┌─toIPv4(byteSwap(toUInt32(toIPv4('205.251.199.199'))))─┐
│ 199.199.251.205                                       │
└───────────────────────────────────────────────────────┘
```

**구문**

```sql theme={null}
byteSwap(x)
```

**인수**

* `x` — 정수형 값입니다. [`(U)Int*`](/ko/reference/data-types/int-uint)

**반환 값**

바이트 순서가 뒤바뀐 `x`를 반환합니다. [`(U)Int*`](/ko/reference/data-types/int-uint)

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT byteSwap(3351772109)
```

```response title=Response theme={null}
3455829959
```

**8비트**

```sql title=Query theme={null}
SELECT byteSwap(54)
```

```response title=Response theme={null}
54
```

**16비트**

```sql title=Query theme={null}
SELECT byteSwap(4135)
```

```response title=Response theme={null}
10000
```

**32비트**

```sql title=Query theme={null}
SELECT byteSwap(3351772109)
```

```response title=Response theme={null}
3455829959
```

**64비트**

```sql title=Query theme={null}
SELECT byteSwap(123294967295)
```

```response title=Response theme={null}
18439412204227788800
```

## divide

도입 버전: v1.1.0

두 값 `a`와 `b`의 몫을 계산합니다. 결과 타입은 항상 [Float64](/ko/reference/data-types/float)입니다.
정수 나눗셈에는 `intDiv` 함수를 사용합니다.

<Note>
  `0`으로 나누면 `inf`, `-inf` 또는 `nan`이 반환됩니다.
</Note>

**구문**

```sql theme={null}
divide(x, y)
```

**인수**

* `x` — 피제수 - `y` — 제수

**반환 값**

x와 y를 나눈 몫

**예시**

**두 수 나누기**

```sql title=Query theme={null}
SELECT divide(25,5) AS quotient, toTypeName(quotient)
```

```response title=Response theme={null}
5	Float64
```

**0으로 나누기**

```sql title=Query theme={null}
SELECT divide(25,0)
```

```response title=Response theme={null}
inf
```

## divideDecimal

도입 버전: v22.12.0

두 개의 Decimal 값에 대해 나눗셈을 수행합니다. 결과 값은 [Decimal256](/ko/reference/data-types/decimal) 타입입니다.
결과 스케일은 `result_scale` 인수(const Integer, 범위 `[0, 76]`)로 명시적으로 지정할 수 있습니다. 지정하지 않으면 결과 스케일은 주어진 인수 중 최댓값이 됩니다.

<Note>
  이 함수는 일반적인 `divide`보다 훨씬 느리게 동작합니다.
  정밀도를 제어할 필요가 없거나 빠른 계산이 필요하다면 [divide](#divide) 사용을 고려하십시오.
</Note>

**구문**

```sql theme={null}
divideDecimal(x, y[, result_scale])
```

**인수**

* `x` — 첫 번째 값: [Decimal](/ko/reference/data-types/decimal). - `y` — 두 번째 값: [Decimal](/ko/reference/data-types/decimal). - `result_scale` — 결과의 스케일입니다. 유형은 [Int/UInt](/ko/reference/data-types/int-uint)입니다.

**반환 값**

지정된 스케일이 적용된 나눗셈 결과입니다. [`Decimal256`](/ko/reference/data-types/decimal)

**예시**

**예시 1**

```sql title=Query theme={null}
SELECT divideDecimal(toDecimal256(-12, 0), toDecimal32(2.1, 1), 10)
```

```response title=Response theme={null}
┌─divideDecimal(toDecimal256(-12, 0), toDecimal32(2.1, 1), 10)─┐
│                                                -5.7142857142 │
└──────────────────────────────────────────────────────────────┘
```

**예시 2**

```sql title=Query theme={null}
SELECT toDecimal64(-12, 1) / toDecimal32(2.1, 1);
SELECT toDecimal64(-12, 1) as a, toDecimal32(2.1, 1) as b, divideDecimal(a, b, 1), divideDecimal(a, b, 5);
```

```response title=Response theme={null}
┌─divide(toDecimal64(-12, 1), toDecimal32(2.1, 1))─┐
│                                             -5.7 │
└──────────────────────────────────────────────────┘
┌───a─┬───b─┬─divideDecimal(a, b, 1)─┬─divideDecimal(a, b, 5)─┐
│ -12 │ 2.1 │                   -5.7 │               -5.71428 │
└─────┴─────┴────────────────────────┴────────────────────────┘
```

## divideOrNull

도입 버전: v25.5.0

`divide`와 동일하지만 0으로 나누면 NULL을 반환합니다.

**구문**

```sql theme={null}
divideOrNull(x, y)
```

**인수**

* `x` — 피제수 - `y` — 제수

**반환 값**

x를 y로 나눈 몫 또는 NULL입니다.

**예시**

**0으로 나누기**

```sql title=Query theme={null}
SELECT divideOrNull(25, 0)
```

```response title=Response theme={null}
\N
```

## gcd

도입 버전: v1.1.0

두 값 a와 b의 최대공약수를 반환합니다.

0으로 나누거나 가장 작은 음수를 -1로 나누면 예외가 발생합니다.

**구문**

```sql theme={null}
gcd(x, y)
```

**인수**

* `x` — 첫 번째 정수 - `y` — 두 번째 정수

**반환 값**

`x`와 `y`의 최대공약수입니다.

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT gcd(12, 18)
```

```response title=Response theme={null}
6
```

## ifNotFinite

도입 버전: v20.3.0

부동소수점 값이 유한한지 검사합니다.

[삼항 연산자](/ko/reference/functions/regular-functions/conditional-functions#if)를 사용하면 유사한 결과를 얻을 수 있습니다: `isFinite(x) ? x : y`.

**구문**

```sql theme={null}
ifNotFinite(x,y)
```

**인수**

* `x` — 무한인지 확인할 값. [`Float*`](/ko/reference/data-types/float)
* `y` — 폴백 값. [`Float*`](/ko/reference/data-types/float)

**반환 값**

* `x`가 유한하면 `x`
* `x`가 유한하지 않으면 `y`

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT 1/0 AS infimum, ifNotFinite(infimum,42)
```

```response title=Response theme={null}
inf	42
```

## intDiv

도입 버전: v1.1.0

두 값 `x`를 `y`로 나누는 정수 나눗셈을 수행합니다. 즉,
몫을 내림하여 가장 가까운 작은 정수로 계산합니다.

결과는 피제수(첫 번째 매개변수)와 동일한 비트를 가집니다.

0으로 나누는 경우, 몫이 피제수의 표현 범위에 맞지 않는 경우,
또는 가장 작은 음수를 -1로 나누는 경우 예외가 발생합니다.

**구문**

```sql theme={null}
intDiv(x, y)
```

**인수**

* `x` — 왼쪽 피연산자. - `y` — 오른쪽 피연산자.

**반환 값**

`x`와 `y`를 정수 나눗셈한 결과

**예시**

**두 개의 float에 대한 정수 나눗셈**

```sql title=Query theme={null}
SELECT intDiv(toFloat64(1), 0.001) AS res, toTypeName(res)
```

```response title=Response theme={null}
┌──res─┬─toTypeName(res)─┐
│ 1000 │ Int64           │
└──────┴─────────────────┘
```

**몫이 피제수의 표현 범위를 벗어납니다**

```sql title=Query theme={null}
SELECT
intDiv(1, 0.001) AS res,
toTypeName(res)
```

```response title=Response theme={null}
Received exception from server (version 23.2.1):
Code: 153. DB::Exception: Received from localhost:9000. DB::Exception:
Cannot perform integer division, because it will produce infinite or too
large number: While processing intDiv(1, 0.001) AS res, toTypeName(res).
(ILLEGAL_DIVISION)
```

## intDivOrNull

도입 버전: v25.5.0

`intDiv`와 동일하지만, 0으로 나누거나 가장 작은 음수를 -1로 나누는 경우에는 NULL을 반환합니다.

**구문**

```sql theme={null}
intDivOrNull(x, y)
```

**인수**

* `x` — 왼쪽 피연산자. [`(U)Int*`](/ko/reference/data-types/int-uint)
* `y` — 오른쪽 피연산자. [`(U)Int*`](/ko/reference/data-types/int-uint)

**반환 값**

`x`를 `y`로 정수 나눗셈한 결과 또는 NULL입니다.

**예시**

**0으로 나눌 때의 정수 나눗셈**

```sql title=Query theme={null}
SELECT intDivOrNull(1, 0)
```

```response title=Response theme={null}
\N
```

**최솟값인 음수를 -1로 나누기**

```sql title=Query theme={null}
SELECT intDivOrNull(-9223372036854775808, -1)
```

```response title=Response theme={null}
\N
```

## intDivOrZero

도입 버전: v1.1.0

`intDiv`와 동일하지만, 0으로 나누거나 가장 작은 음수를 -1로 나눌 경우 0을 반환합니다.

**구문**

```sql theme={null}
intDivOrZero(a, b)
```

**인수**

* `a` — 왼쪽 피연산자. [`(U)Int*`](/ko/reference/data-types/int-uint)
* `b` — 오른쪽 피연산자. [`(U)Int*`](/ko/reference/data-types/int-uint)

**반환 값**

a와 b를 정수 나눗셈한 결과 또는 0입니다.

**예시**

**0으로 나누는 정수 나눗셈**

```sql title=Query theme={null}
SELECT intDivOrZero(1, 0)
```

```response title=Response theme={null}
0
```

**가장 작은 음수를 -1로 나누기**

```sql title=Query theme={null}
SELECT intDivOrZero(0.05, -1)
```

```response title=Response theme={null}
0
```

## isFinite

도입 버전: v1.1.0

Float32 또는 Float64, 또는 BFloat16 인수가 무한대가 아니고 `NaN`도 아니면 `1`을 반환하며,
그렇지 않으면 `0`을 반환합니다.

**구문**

```sql theme={null}
isFinite(x)
```

**인수**

* `x` — 유한한 값인지 확인할 숫자입니다. [`Float*`](/ko/reference/data-types/float) 또는 [`BFloat16`](/ko/reference/data-types/float)

**반환 값**

x가 무한대가 아니고 `NaN`도 아니면 `1`이고, 그렇지 않으면 `0`입니다.

**예시**

**숫자가 유한한지 확인**

```sql title=Query theme={null}
SELECT isFinite(inf)
```

```response title=Response theme={null}
0
```

## isInfinite

도입 버전: v1.1.0

Float32 또는 Float64, 또는 BFloat16 인수가 무한대이면 `1`을 반환하고, 그렇지 않으면 `0`을 반환합니다.
`NaN`의 경우에는 `0`을 반환합니다.

**구문**

```sql theme={null}
isInfinite(x)
```

**인수**

* `x` — 무한 여부를 확인할 숫자입니다. [`Float*`](/ko/reference/data-types/float) 또는 [`BFloat16`](/ko/reference/data-types/float)

**반환 값**

`x`가 무한대이면 `1`, 그렇지 않으면 `0`입니다(`NaN`인 경우 포함).

**예시**

**숫자가 무한대인지 확인**

```sql title=Query theme={null}
SELECT isInfinite(inf), isInfinite(NaN), isInfinite(10)
```

```response title=Response theme={null}
1	0	0
```

## isNaN

도입 버전: v1.1.0

Float32 또는 Float64, 또는 BFloat16 인수가 `NaN`이면 `1`을, 그렇지 않으면 `0`을 반환합니다.

**구문**

```sql theme={null}
isNaN(x)
```

**인수**

* `x` — `NaN`인지 여부를 평가할 인수입니다. [`Float*`](/ko/reference/data-types/float) 또는 [`BFloat16`](/ko/reference/data-types/float)

**반환 값**

`NaN`이면 `1`, 그렇지 않으면 `0`입니다.

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT isNaN(NaN)
```

```response title=Response theme={null}
1
```

## kqlBin

도입 버전: v26.8.0

Kusto Query Language의 `bin()`과 동일하게, 값을 `roundTo`의 배수로 내림합니다.

규칙은 인수 타입에 따라 달라집니다. 숫자는 산술적으로 내림되고, timespan(`Interval` 타입)은 timespan 단위로, datetime 역시 timespan 단위로 내림됩니다. KQL의 datetime은 `DateTime64`이며, 표현 범위가 더 좁은 `DateTime`과 `Date` 타입은 KQL datetime이 만들어낼 수 있는 모든 빈을 표현할 수 없으므로 허용되지 않습니다.

이 함수는 `dialect = 'kusto'`일 때 `bin()`의 구현을 담당합니다. SQL에서 직접 호출하기 위한 용도가 아닙니다.

**구문**

```sql theme={null}
kqlBin(value, roundTo)
```

**인수**

* `value` — 숫자, timespan 또는 datetime(`DateTime64`)입니다. - `roundTo` — 빈 크기입니다.

**반환 값**

`roundTo`의 배수 중 가장 가까운 값으로 내림한 `value`입니다.

**예시**

**number**

```sql title=Query theme={null}
SELECT kqlBin(4.5, 1)
```

```response title=Response theme={null}
4
```

**timespan**

```sql title=Query theme={null}
SELECT kqlBin(toIntervalNanosecond(16 * 86400000000000), toIntervalNanosecond(7 * 86400000000000))
```

```response title=Response theme={null}
1209600000000000
```

**datetime**

```sql title=Query theme={null}
SELECT kqlBin(toDateTime64('2026-08-01 12:34:56', 7, 'UTC'), toIntervalHour(1))
```

```response title=Response theme={null}
2026-08-01 12:00:00.0000000
```

## kqlBinAt

도입 버전: v26.8.0

Kusto Query Language의 `bin_at()`과 마찬가지로, `fixedPoint`부터 세어 `binSize`의 배수가 되도록 값을 내림합니다. 빈은 기준 시점의 앞쪽 또는 뒤쪽으로 정렬될 수 있습니다.

적용되는 규칙은 인수 타입에 따라 다릅니다. 숫자는 산술적으로 내림되고, timespan(즉 `Interval`)은 timespan 단위로 내림되며, datetime은 datetime 기준 시점부터 세어 timespan 단위로 내림됩니다. KQL datetime은 `DateTime64`입니다. 표현 범위가 더 좁은 `DateTime` 및 `Date` 타입은 KQL datetime이 만들어낼 수 있는 모든 빈을 표현할 수 없으므로 허용되지 않습니다.

이 함수는 `dialect = 'kusto'`일 때 `bin_at()`의 구현을 담당합니다. SQL에서 직접 호출하기 위한 함수가 아닙니다.

**구문**

```sql theme={null}
kqlBinAt(value, binSize, fixedPoint)
```

**인수**

* `value` — 숫자, timespan 또는 datetime(`DateTime64`). - `binSize` — 빈 크기. - `fixedPoint` — 빈을 세기 시작하는 기준점.

**반환 값**

`fixedPoint`를 기준으로 세었을 때 `binSize`의 가장 가까운 배수로 내림한 `value`.

**예시**

**number**

```sql title=Query theme={null}
SELECT kqlBinAt(6.5, 2.5, -0.5)
```

```response title=Response theme={null}
4.5
```

**datetime**

```sql title=Query theme={null}
SELECT kqlBinAt(toDateTime64('2026-08-01 12:34:56', 7, 'UTC'), toIntervalHour(1), toDateTime64('2026-08-01 00:30:00', 7, 'UTC'))
```

```response title=Response theme={null}
2026-08-01 12:30:00.0000000
```

## kqlDateTimeBinAt

도입 버전: v26.8.0

datetime 값을 기준 시점(fixed point)부터 계산한 timespan의 배수로 내림합니다.

**구문**

```sql theme={null}
kqlDateTimeBinAt(value, binSize, fixedPoint)
```

**인수**

* `value` — 내림할 datetime. - `binSize` — timespan 빈 크기. - `fixedPoint` — datetime 기준 시점.

**반환 값**

내림된 datetime.

**예시**

## kqlDivide

도입 버전: v26.8.0

Kusto Query Language에서 정의하는 나눗셈입니다. 정수 피연산자 두 개를 나누면 결과도 정수이므로 `7 / 2`는 `3`이 되고, 타임스팬 피연산자 두 개(`Interval` 값)를 나누면 실수 비율이 되므로 `15ms / 10ms`는 `1.5`가 됩니다. 그 외의 피연산자 타입 조합은 [`divide`](#divide)와 동일하게 나눕니다.

이 함수는 `dialect = 'kusto'`일 때 `/` 연산자의 동작을 구현합니다. SQL에서 직접 호출하기 위한 함수가 아닙니다.

**구문**

```sql theme={null}
kqlDivide(x, y)
```

**인수**

* `x` — 피제수입니다. - `y` — 제수입니다.

**반환 값**

두 인수가 모두 정수이면 `intDiv(x, y)`, 두 인수가 모두 인터벌이면 인터벌의 틱 비율, 그 외에는 `divide(x, y)`를 반환합니다.

**예시**

**정수**

```sql title=Query theme={null}
SELECT kqlDivide(7, 2)
```

```response title=Response theme={null}
3
```

**실수**

```sql title=Query theme={null}
SELECT kqlDivide(7.0, 2)
```

```response title=Response theme={null}
3.5
```

**타임스팬**

```sql title=Query theme={null}
SELECT kqlDivide(toIntervalNanosecond(15000000), toIntervalNanosecond(10000000))
```

```response title=Response theme={null}
1.5
```

## kqlMultiply

Introduced in: v26.8.0

Kusto Query Language에서 정의하는 방식의 곱셈입니다. 타임스팬(`Interval`)은 어느 쪽에 있는 숫자와도 곱해져 배율이 조정되므로, `2 * 1h`는 2시간이 됩니다. 인터벌이 없는 두 인수는 [`multiply`](#multiply)와 동일하게 곱해집니다.

이 함수는 `dialect = 'kusto'`일 때 `*` 연산자의 구현을 담당합니다. SQL에서 직접 호출하기 위한 함수가 아닙니다.

**구문**

```sql theme={null}
kqlMultiply(x, y)
```

**인수**

* `x` — 숫자 또는 타임스팬. - `y` — 숫자, 또는 `x`가 숫자인 경우 타임스팬.

**반환 값**

두 값의 곱을 반환하며, 두 인수 중 하나가 인터벌이면 동일한 종류의 인터벌을 반환합니다.

**예시**

**타임스팬**

```sql title=Query theme={null}
SELECT kqlMultiply(2, toIntervalNanosecond(3600000000000))
```

```response title=Response theme={null}
7200000000000
```

**numbers**

```sql title=Query theme={null}
SELECT kqlMultiply(6, 7)
```

```response title=Response theme={null}
42
```

## kqlRangeCount

도입 버전: v26.8.0

Kusto Query Language의 `range` 소스가 생성하는 행 수로, `floor((to - from)
/ step) + 1`이며 절대 0보다 작아지지 않습니다. 경계와 간격은 숫자이거나, 타임스팬(`Interval`) 단위로
증가하는 datetime이거나, 타임스팬입니다. 시간 형식은 정수 나노초 단위로 계산되는데, 이는 ClickHouse의
단일 나눗셈만으로는 표현할 수 없습니다. 정수와 Decimal 값은 `Float64`를 거치지 않고 정확하게 계산됩니다.

이 함수는 `dialect = 'kusto'`일 때 `range` 소스의 동작을 구현합니다. SQL에서 직접 호출하기 위한
함수는 아닙니다.

**구문**

```sql theme={null}
kqlRangeCount(from, to, step)
```

**인수**

* `from` — 범위의 첫 번째 값입니다. - `to` — 범위가 초과하지 않는 값입니다. - `step` — 연속된 두 값 사이의 차이입니다.

**반환 값**

범위에 포함된 값의 개수입니다.

**예시**

**numbers**

```sql title=Query theme={null}
SELECT kqlRangeCount(1, 7, 2)
```

```response title=Response theme={null}
4
```

**datetimes**

```sql title=Query theme={null}
SELECT kqlRangeCount(toDateTime64('2026-08-01 00:00:00', 7, 'UTC'), toDateTime64('2026-08-01 12:00:00', 7, 'UTC'), toIntervalHour(5))
```

```response title=Response theme={null}
3
```

## lcm

도입 버전: v1.1.0

두 값 `x`와 `y`의 최소공배수를 반환합니다.

0으로 나누거나, 표현 가능한 가장 작은 음수를 -1로 나누면 예외가 발생합니다.

**구문**

```sql theme={null}
lcm(x, y)
```

**인수**

* `x` — 첫 번째 정수입니다. [`(U)Int*`](/ko/reference/data-types/int-uint)
* `y` — 두 번째 정수입니다. [`(U)Int*`](/ko/reference/data-types/int-uint)

**반환 값**

`x`와 `y`의 최소공배수를 반환합니다. [`(U)Int*`](/ko/reference/data-types/int-uint)

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT lcm(6, 8)
```

```response title=Response theme={null}
24
```

## max2

도입 버전: v21.11.0

두 숫자 값 `x`와 `y` 중에서 더 큰 값을 반환합니다.

**구문**

```sql theme={null}
max2(x, y)
```

**인수**

* `x` — 첫 번째 값 [`(U)Int8/16/32/64`](/ko/reference/data-types/int-uint), [`Float*`](/ko/reference/data-types/float), [`BFloat16`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)
* `y` — 두 번째 값 [`(U)Int8/16/32/64`](/ko/reference/data-types/int-uint), [`Float*`](/ko/reference/data-types/float), [`BFloat16`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)

**반환 값**

`x`와 `y` 중 더 큰 값을 반환합니다. [`Float64`](/ko/reference/data-types/float)

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT max2(-1, 2)
```

```response title=Response theme={null}
2
```

## midpoint

도입 버전: v25.11.0

제공된 인수의 평균값을 계산해 반환합니다.
숫자 및 시간 타입을 지원합니다.

**구문**

```sql theme={null}
midpoint(x1[, x2, ...])
```

**인수**

* `x1[, x2, ...]` — 평균을 계산할 단일 값 또는 여러 값을 받습니다.

**반환 값**

주어진 인수의 평균값을 반환하며, 가장 큰 호환 타입으로 승격됩니다.

**예시**

**숫자 타입**

```sql title=Query theme={null}
SELECT midpoint(1, toUInt8(3), 0.5) AS result, toTypeName(result) AS type;
-- 반환 유형은 Float64입니다. UInt8이 비교를 위해 64비트로 승격되어야 하기 때문입니다.
```

```response title=Response theme={null}
┌─result─┬─type────┐
│    1.5 │ Float64 │
└────────┴─────────┘
```

**Decimal 타입**

```sql title=Query theme={null}
SELECT midpoint(toDecimal32(1.5, 2), toDecimal32(1, 1), 2) AS result, toTypeName(result) AS type;
```

```response title=Response theme={null}
┌─result─┬─type──────────┐
│    1.5 │ Decimal(9, 2) │
└────────┴───────────────┘
```

**날짜 타입**

```sql title=Query theme={null}
SELECT midpoint(toDate('2025-01-01'), toDate('2025-01-05')) AS result, toTypeName(result) AS type;
```

```response title=Response theme={null}
┌─────result─┬─type─┐
│ 2025-01-03 │ Date │
└────────────┴──────┘
```

**DateTime 타입**

```sql title=Query theme={null}
SELECT midpoint(toDateTime('2025-01-01 00:00:00'), toDateTime('2025-01-03 12:00:00')) AS result, toTypeName(result) AS type;
```

```response title=Response theme={null}
┌──────────────result─┬─type─────┐
│ 2025-01-02 06:00:00 │ DateTime │
└─────────────────────┴──────────┘
```

**Time64 타입**

```sql title=Query theme={null}
SELECT midpoint(toTime64('12:00:00', 0), toTime64('14:00:00', 0)) AS result, toTypeName(result) AS type;
```

```response title=Response theme={null}
┌───result─┬─type──────┐
│ 13:00:00 │ Time64(0) │
└──────────┴───────────┘
```

## min2

도입된 버전: v21.11.0

두 숫자 값 `x`와 `y` 중 더 작은 값을 반환합니다.

**구문**

```sql theme={null}
min2(x, y)
```

**인수**

* `x` — 첫 번째 값: [`(U)Int8/16/32/64`](/ko/reference/data-types/int-uint), [`Float*`](/ko/reference/data-types/float), [`BFloat16`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)
* `y` — 두 번째 값: [`(U)Int8/16/32/64`](/ko/reference/data-types/int-uint), [`Float*`](/ko/reference/data-types/float), [`BFloat16`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)

**반환 값**

`x`와 `y` 중 더 작은 값을 반환합니다. [`Float64`](/ko/reference/data-types/float)

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT min2(-1, 2)
```

```response title=Response theme={null}
-1
```

## minus

도입 버전: v1.1.0

두 값 `a`와 `b`의 차이를 계산합니다. 결과는 항상 부호 있는 값입니다.
plus와 마찬가지로, date 또는 날짜/시간 값에서 정수를 뺄 수 있습니다.
또한 날짜/시간 값 간의 뺄셈도 지원하며, 이 경우 두 값 사이의 시간 차이가 반환됩니다.
`DateTime` 또는 `DateTime64`에서 `Time` 또는 `Time64`를 빼는 것도 가능하며,
시간 값은 초 단위 오프셋으로 적용됩니다. `DateTime`에서 `Time`을 빼면 `DateTime`이
반환되고, `DateTime64` 또는 `Time64`가 포함된 조합은 두 인수 중 최대 scale을 가진
`DateTime64`를 반환합니다.

**구문**

```sql theme={null}
minus(x, y)
```

**인수**

* `x` — 피감수. - `y` — 감수.

**반환 값**

x에서 y를 뺀 값

**예시**

**두 수 빼기**

```sql title=Query theme={null}
SELECT minus(10, 5)
```

```response title=Response theme={null}
5
```

**정수와 날짜의 뺄셈**

```sql title=Query theme={null}
SELECT minus(toDate('2025-01-01'),5)
```

```response title=Response theme={null}
2024-12-27
```

## modulo

도입 버전: v1.1.0

두 값 a를 b로 나눈 나머지를 계산합니다.

두 입력이 모두 정수이면 결과 유형은 정수입니다. 입력 중 하나가
부동소수점 수이면 결과 유형은 Float64입니다.

나머지는 C++와 같은 방식으로 계산됩니다. 음수는 버림 나눗셈으로
계산합니다.

0으로 나누거나 가장 작은 음수를 -1로 나누면
예외가 발생합니다.

**구문**

```sql theme={null}
modulo(a, b)
```

**별칭**: `mod`

**인수**

* `a` — 피제수 - `b` — 제수(모듈러스)

**반환 값**

a % b의 나머지입니다.

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT modulo(5, 2)
```

```response title=Response theme={null}
1
```

## moduloLegacy

도입 버전: v1.1.0

나눗셈의 나머지를 계산합니다. 이 함수는 C++ `%` 연산자를 사용하는 레거시 modulo 구현이며, 인수가 음수이면 결과도 음수가 될 수 있습니다. 이 함수는 이전 테이블 파티셔닝 로직과의 하위 호환성을 위해 제공됩니다. 표준 동작이 필요하면 `modulo` 또는 `positiveModulo`를 사용하십시오.

**구문**

```sql theme={null}
moduloLegacy(a, b)
```

**인수**

* `a` — 피제수입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float)
* `b` — 나누는 수입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float)

**반환 값**

나눗셈의 나머지를 반환합니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float)

**예시**

**기본 사용법**

```sql title=Query theme={null}
SELECT moduloLegacy(10, 3)
```

```response title=Response theme={null}
1
```

## moduloOrNull

도입 버전: v25.5.0

`a`를 `b`로 나눌 때의 나머지를 계산합니다. 함수 `modulo`와 유사하지만, `moduloOrNull`은 연산 시 부동소수점 예외가 발생하는 경우 `NULL`을 반환합니다.
부동소수점 인수의 경우 이는 제수가 `0`일 때만 발생합니다. 정수 인수의 경우에는 최소 음수 값을 `-1`로 나눈 나머지까지 추가로 포함합니다(예: `Int8`의 `-128 % -1`).

**구문**

```sql theme={null}
moduloOrNull(x, y)
```

**별칭**: `modOrNull`

**인수**

* `x` — 피제수입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float)
* `y` — 제수(모듈러스)입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float)

**반환 값**

연산으로 인해 부동소수점 예외가 발생하는 경우 `NULL`을 반환하고, 그렇지 않으면 `x`를 `y`로 나눈 나머지를 반환합니다.
즉, 제수가 0이거나, 정수 인수의 경우 최소 음수 값을 `-1`로 modulo 연산할 때입니다.

**예시**

**제수가 0일 때의 moduloOrNull**

```sql title=Query theme={null}
SELECT moduloOrNull(5, 0)
```

```response title=Response theme={null}
\N
```

**최소 음수 정수를 -1로 나눌 때의 moduloOrNull**

```sql title=Query theme={null}
SELECT moduloOrNull(toInt8(-128), toInt8(-1))
```

```response title=Response theme={null}
\N
```

## moduloOrZero

도입 버전: v20.3.0

`modulo`와 유사하지만, 정수 결과에서 연산이 예외를 발생시킬 상황에서는
예외 대신 0을 반환합니다. 부동 소수점 결과에서는 제수가 0이면 `NaN`이 반환됩니다.

**구문**

```sql theme={null}
moduloOrZero(a, b)
```

**인수**

* `a` — 피제수입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float)
* `b` — 제수(모듈러스)입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float)

**반환 값**

`a % b`의 나머지를 반환합니다. 정수 결과에서는 원래라면 예외가 발생할 연산에 대해 `0`을 반환합니다.
부동소수점 결과에서는 제수가 0이면 `NaN`이 반환됩니다.

**예시**

**정수 제수가 0인 경우**

```sql title=Query theme={null}
SELECT moduloOrZero(5, 0)
```

```response title=Response theme={null}
0
```

**부동소수점 제수가 0인 경우**

```sql title=Query theme={null}
SELECT moduloOrZero(toFloat64(5), toFloat64(0))
```

```response title=Response theme={null}
nan
```

## multiply

도입 버전: v1.1.0

두 값 `x`와 `y`를 곱한 결과를 계산합니다.

**구문**

```sql theme={null}
multiply(x, y)
```

**인수**

* `x` — 곱할 값입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)
* `y` — 곱할 값입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)

**반환 값**

x와 y의 곱을 반환합니다.

**예시**

**두 수를 곱하기**

```sql title=Query theme={null}
SELECT multiply(5,5)
```

```response title=Response theme={null}
25
```

## multiplyDecimal

도입 버전: v22.12.0

두 개의 Decimal 값에 대해 곱셈을 수행합니다. 결과 값의 유형은 [Decimal256](/ko/reference/data-types/decimal)입니다.
결과 스케일은 `result_scale` 인수(범위 `[0, 76]`의 상수 Integer)로 명시적으로 지정할 수 있습니다. 지정하지 않으면 결과 스케일은 주어진 인수 중 최대 스케일이 됩니다.

<Note>
  이 함수들은 일반적인 `multiply`보다 훨씬 느리게 동작합니다.
  정밀도를 제어할 필요가 없거나 빠른 계산이 필요하다면 [multiply](#multiply) 사용을 고려하십시오.
</Note>

**구문**

```sql theme={null}
multiplyDecimal(a, b[, result_scale])
```

**인수**

* `a` — 첫 번째 값입니다. [`Decimal`](/ko/reference/data-types/decimal)
* `b` — 두 번째 값입니다. [`Decimal`](/ko/reference/data-types/decimal)
* `result_scale` — 결과의 scale입니다. [`(U)Int*`](/ko/reference/data-types/int-uint)

**반환 값**

지정된 scale로 곱셈한 결과입니다. 유형: [`Decimal256`](/ko/reference/data-types/decimal)

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT multiplyDecimal(toDecimal256(-12, 0), toDecimal32(-2.1, 1), 1)
```

```response title=Response theme={null}
25.2
```

**일반 곱셈과의 차이점**

```sql title=Query theme={null}
SELECT multiply(toDecimal64(-12.647, 3), toDecimal32(2.1239, 4));
SELECT multiplyDecimal(toDecimal64(-12.647, 3), toDecimal32(2.1239, 4));
```

```response title=Response theme={null}
┌─multiply(toDecimal64(-12.647, 3), toDecimal32(2.1239, 4))─┐
│                                               -26.8609633 │
└───────────────────────────────────────────────────────────┘
┌─multiplyDecimal(toDecimal64(-12.647, 3), toDecimal32(2.1239, 4))─┐
│                                                         -26.8609 │
└──────────────────────────────────────────────────────────────────┘
```

**multiplyDecimal 사용 시 오버플로우 없음**

```sql title=Query theme={null}
SELECT
    toDecimal64(-12.647987876, 9) AS a,
    toDecimal64(123.967645643, 9) AS b,
    multiplyDecimal(a, b);
```

```response title=Response theme={null}
┌─────────────a─┬─────────────b─┬─multiplyDecimal(a, b)─┐
│ -12.647987876 │ 123.967645643 │       -1567.941279108 │
└───────────────┴───────────────┴───────────────────────┘
```

**일반 곱셈에서의 Decimal 오버플로우**

```sql title=Query theme={null}
SELECT
    toDecimal64(-12.647987876, 9) AS a,
    toDecimal64(123.967645643, 9) AS b,
    a * b;
```

```response title=Response theme={null}
Received exception:
Code: 407. DB::Exception: Decimal math overflow. (DECIMAL_OVERFLOW)
```

## negate

도입 버전: v1.1.0

인수 `x`의 부호를 반대로 바꿉니다. 결과는 항상 부호 있는 형식입니다.

**구문**

```sql theme={null}
negate(x)
```

**인수**

* `x` — 부호를 반전할 값입니다.

**반환 값**

x의 부호를 반전한 값인 -x를 반환합니다.

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT negate(10)
```

```response title=Response theme={null}
-10
```

## plus

도입된 버전: v1.1.0

두 값 `x`와 `y`의 합을 계산합니다. 별칭: `x + y` (연산자)입니다.
정수와 날짜 또는 날짜/시간 값을 더할 수도 있습니다. 전자의 경우
날짜의 일 수가 증가하고, 후자의 경우
날짜/시간 값의 초 수가 증가합니다.
날짜와 시간도 더할 수 있습니다. `Date`와 `Time`을 더하면
`DateTime`이 됩니다. `Date`와 `Time64`를 더하거나, `Date32`와
`Time` 또는 `Time64`를 더하면 `DateTime64`가 됩니다.
`DateTime` 또는 `DateTime64`에 `Time` 또는 `Time64`를 더하면 해당 시간
값이 초 단위 오프셋으로 적용됩니다. `DateTime`에 `Time`을 더하면 `DateTime`이 되고,
`DateTime64` 또는 `Time64`가 포함된 조합은 두 인수 중 최대 scale을 가진
`DateTime64`가 됩니다.

**구문**

```sql theme={null}
plus(x, y)
```

**인수**

* `x` — 왼쪽 피연산자. - `y` — 오른쪽 피연산자.

**반환 값**

x와 y를 더한 값을 반환합니다

**예시**

**두 숫자 더하기**

```sql title=Query theme={null}
SELECT plus(5,5)
```

```response title=Response theme={null}
10
```

**정수와 날짜 더하기**

```sql title=Query theme={null}
SELECT plus(toDate('2025-01-01'),5)
```

```response title=Response theme={null}
2025-01-06
```

**날짜 및 시간 추가**

```sql title=Query theme={null}
SELECT toDate('2025-01-01') + CAST('14:30:25', 'Time')
```

```response title=Response theme={null}
2025-01-01 14:30:25
```

## positiveModulo

도입 버전: v22.11.0

`x`를 `y`로 나눌 때의 나머지를 계산합니다. `modulo` 함수와
유사하지만 `positiveModulo`는 항상 음수가 아닌 값을 반환합니다.

**구문**

```sql theme={null}
positiveModulo(x, y)
```

**별칭**: `positive_modulo`, `pmod`

**인수**

* `x` — 피제수입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)
* `y` — 제수(모듈러스)입니다. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)

**반환 값**

`x`에서 `y`로 나누어떨어지는 `x` 이하의 가장 가까운 정수를 뺀 값을 반환합니다.

**예시**

**사용 예시**

```sql title=Query theme={null}
SELECT positiveModulo(-1, 10)
```

```response title=Response theme={null}
9
```

## positiveModuloOrNull

도입 버전: v25.5.0

`a`를 `b`로 나눌 때의 나머지를 계산합니다. 함수 `positiveModulo`와 유사하지만, `positiveModuloOrNull`은 연산 시 부동소수점 예외가 발생하는 경우 `NULL`을 반환합니다.
부동소수점 인수에서는 제수가 `0`일 때만 이런 일이 발생합니다. 정수 인수에서는 여기에 더해 최소 음수 값을 `-1`로 나눈 modulo도 포함됩니다(예: `Int8`의 `-128 % -1`).

**구문**

```sql theme={null}
positiveModuloOrNull(x, y)
```

**별칭**: `positive_modulo_or_null`, `pmodOrNull`

**인수**

* `x` — 피제수입니다. [`(U)Int*`](/ko/reference/data-types/int-uint)/[`Float32/64`](/ko/reference/data-types/float). - `y` — 제수(모듈러스)입니다. [`(U)Int*`](/ko/reference/data-types/int-uint)/[`Float32/64`](/ko/reference/data-types/float).

**반환 값**

`x`에서 `y`로 나누어떨어지는 `x` 이하의 가장 큰 정수를 뺀 값을 반환합니다. 또는 연산 중 부동소수점 예외가 발생하는 경우 `NULL`을 반환합니다. 즉, 제수가 0이거나, 정수 인수의 경우 최소 음수 값을 `-1`로 modulo 연산할 때입니다.

**예시**

**0으로 나누는 positiveModuloOrNull**

```sql title=Query theme={null}
SELECT positiveModuloOrNull(5, 0)
```

```response title=Response theme={null}
\N
```

**최소 음의 정수를 -1로 나눌 때의 positiveModuloOrNull**

```sql title=Query theme={null}
SELECT positiveModuloOrNull(toInt8(-128), toInt8(-1))
```

```response title=Response theme={null}
\N
```

## sqr

도입 버전: v26.7.0

값 `x`의 제곱을 계산합니다.

**구문**

```sql theme={null}
sqr(x)
```

**인수**

* `x` — 제곱할 값. [`(U)Int*`](/ko/reference/data-types/int-uint) 또는 [`Float*`](/ko/reference/data-types/float) 또는 [`Decimal`](/ko/reference/data-types/decimal)

**반환 값**

`x`를 자기 자신으로 곱한 값을 반환합니다.

**예시**

**숫자 제곱하기**

```sql title=Query theme={null}
SELECT sqr(5)
```

```response title=Response theme={null}
25
```
