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

> 计算不同参数值的近似数量。它与 uniqCombined 相同，但对所有数据类型都使用 64 位哈希，而不只是对 String 类型使用。

# uniqCombined64

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

引入版本：v20.1.0

计算不同参数值的近似数量。
它与 [`uniqCombined`](/zh/reference/functions/aggregate-functions/uniqCombined) 相同，但会对所有数据类型使用 64 位哈希，而不只是对 String 类型使用。

此函数提供确定性结果 (不依赖于查询处理顺序) 。

<Note>
  由于它对所有类型都使用 64 位哈希，因此当基数明显大于 `UINT_MAX` 时，结果不会像 [`uniqCombined`](/zh/reference/functions/aggregate-functions/uniqCombined) 那样产生很大的误差；后者对非 String 类型使用的是 32 位哈希。
</Note>

与 [uniq](/zh/reference/functions/aggregate-functions/uniq) 函数相比，uniqCombined64 函数：

* 内存消耗少数倍
* 计算精度高数倍

<Accordion title="实现细节">
  此函数会先为聚合中所有参数的所有数据类型计算 64 位哈希，然后基于该哈希进行计算。
  它结合使用三种算法：数组、哈希表，以及带误差校正表的 [HyperLogLog](https://en.wikipedia.org/wiki/HyperLogLog)：

  * 当不同元素数量较少时，使用数组
  * 当集合大小进一步增大时，使用哈希表
  * 当元素数量更多时，使用 HyperLogLog，此时会占用固定大小的内存
</Accordion>

**语法**

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

**参数**

* `HLL_precision` — 可选。HyperLogLog 中单元数量的以 2 为底对数。默认值为 17，实际约占 96 KiB 空间 (2^17 个单元，每个单元 6 位) 。范围：\[12, 20]。[`UInt8`](/zh/reference/data-types/int-uint)

**实参**

* `x` — 可变数量的参数。[`Tuple(T)`](/zh/reference/data-types/tuple) 或 [`Array(T)`](/zh/reference/data-types/array) 或 [`Date`](/zh/reference/data-types/date) 或 [`DateTime`](/zh/reference/data-types/datetime) 或 [`String`](/zh/reference/data-types/string) 或 [`(U)Int*`](/zh/reference/data-types/int-uint) 或 [`Float*`](/zh/reference/data-types/float) 或 [`Decimal`](/zh/reference/data-types/decimal)

**返回值**

返回一个 `UInt64` 类型的数值，表示不同实参值的近似数量。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**大型数据集示例**

```sql title=Query theme={null}
SELECT uniqCombined64(number) FROM numbers(1e10);
```

```response title=Response theme={null}
┌─uniqCombined64(number)─┐
│             9998568925 │
└────────────────────────┘
```

**与 uniqCombined 的比较**

```sql title=Query theme={null}
-- 使用大数据集的 uniqCombined64
SELECT uniqCombined64(number) FROM numbers(1e10);

-- 使用相同数据集的 uniqCombined 近似效果较差
SELECT uniqCombined(number) FROM numbers(1e10);
```

```response title=Response theme={null}
┌─uniqCombined64(number)─┐
│             9998568925 │ -- 100亿
└────────────────────────┘
┌─uniqCombined(number)─┐
│           5545308725 │ -- 55.5亿
└──────────────────────┘
```

**另见**

* [uniq](/zh/reference/functions/aggregate-functions/uniq)
* [uniqCombined](/zh/reference/functions/aggregate-functions/uniqCombined)
* [uniqHLL12](/zh/reference/functions/aggregate-functions/uniqHLL12)
* [uniqExact](/zh/reference/functions/aggregate-functions/uniqExact)
* [uniqTheta](/zh/reference/functions/aggregate-functions/uniqthetasketch)
