> ## 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.

> 引数の異なる値のおおよその個数を計算します。

# uniq

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

導入バージョン: v1.1.0

引数の異なる値のおおよその数を計算します。

この関数は適応的なサンプリングアルゴリズムを使用します。計算状態には、最大 65536 個の要素ハッシュ値のサンプルを使用します。このアルゴリズムは非常に高精度で、CPU 上でも非常に効率的です。クエリにこの関数が複数含まれている場合でも、uniq の使用速度は他の集約関数とほぼ同等です。

<Accordion title="実装の詳細">
  この関数は、集約内のすべてのパラメータに対してハッシュを計算し、それを計算に使用します。
  適応的なサンプリングアルゴリズムを使用します。
  計算状態には、最大 65536 個の要素ハッシュ値のサンプルを使用します。
  このアルゴリズムは非常に高精度で、CPU 上でも非常に効率的です。
  クエリにこの関数が複数含まれている場合でも、`uniq` の使用速度は他の集約関数とほぼ同等です。
</Accordion>

<Tip>
  ほぼすべての場面で、他のバリアントではなくこの関数を使用することを推奨します。
</Tip>

**構文**

```sql theme={null}
uniq(x[, ...])
```

**引数**

* `x` — この関数は可変個の引数を受け取ります。[`Tuple(T)`](/ja/reference/data-types/tuple) または [`Array(T)`](/ja/reference/data-types/array) または [`Date`](/ja/reference/data-types/date) または [`DateTime`](/ja/reference/data-types/datetime) または [`String`](/ja/reference/data-types/string) または [`(U)Int*`](/ja/reference/data-types/int-uint) または [`Float*`](/ja/reference/data-types/float) または [`Decimal`](/ja/reference/data-types/decimal)

**戻り値**

異なる値のおおよその個数を表す UInt64 型の数値を返します。[`UInt64`](/ja/reference/data-types/int-uint)

**例**

**使用例**

```sql title=Query theme={null}
CREATE TABLE example_table (
    id UInt32,
    category String,
    value Float64
) ENGINE = Memory;

INSERT INTO example_table VALUES
(1, 'A', 10.5),
(2, 'B', 20.3),
(3, 'A', 15.7),
(4, 'C', 8.9),
(5, 'B', 12.1),
(6, 'A', 18.4);

SELECT uniq(category) as unique_categories
FROM example_table;
```

```response title=Response theme={null}
┌─unique_categories─┐
│                 3 │
└───────────────────┘
```

**複数の引数**

```sql title=Query theme={null}
SELECT uniq(category, value) as unique_combinations
FROM example_table;
```

```response title=Response theme={null}
┌─unique_combinations─┐
│                   6 │
└─────────────────────┘
```

**関連項目**

* [uniqCombined](/ja/reference/functions/aggregate-functions/uniqCombined)
* [uniqCombined64](/ja/reference/functions/aggregate-functions/uniqCombined64)
* [uniqHLL12](/ja/reference/functions/aggregate-functions/uniqHLL12)
* [uniqExact](/ja/reference/functions/aggregate-functions/uniqExact)
* [uniqTheta](/ja/reference/functions/aggregate-functions/uniqthetasketch)
