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

> 使用 Theta Sketch Framework 近似计算不同参数值的数量。

# uniqTheta

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

引入版本：v21.6.0

使用 [Theta Sketch Framework](https://datasketches.apache.org/docs/Theta/ThetaSketches.html#theta-sketch-framework) 近似计算不同参数值的数量。

<Accordion title="实现细节">
  此函数会先对聚合中的所有参数计算哈希值，然后将其用于后续计算。
  它使用 [KMV](https://datasketches.apache.org/docs/Theta/InverseEstimate.html) 算法来近似计算不同参数值的数量。

  使用了 4096 (2^12) 个 64 位 sketch。
  状态大小约为 41 KB。

  相对误差为 3.125% (95% 置信度) ，详见[相对误差表](https://datasketches.apache.org/docs/Theta/ThetaErrorTable.html)。
</Accordion>

**语法**

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

**参数**

* `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}
CREATE TABLE example_theta
(
    id UInt32,
    category String
)
ENGINE = Memory;

INSERT INTO example_theta VALUES
(1, 'A'), (2, 'B'), (3, 'A'), (4, 'C'), (5, 'B'), (6, 'A');

SELECT uniqTheta(category) as theta_unique_categories
FROM example_theta;
```

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

**另请参阅**

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