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

> 返回一个数组，其中包含指定列中近似最常见的值及其出现次数。

# approx_top_k

<div id="approx_top_k">
  ## approx\_top\_k
</div>

引入版本：v1.1.0

返回指定列中近似最常见的值及其计数构成的数组。
结果数组按值的近似出现频率降序排序 (而不是按值本身排序) 。

此函数不保证结果一定准确。
在某些情况下，可能会产生误差，并返回出现频繁但并非最频繁的值。

**语法**

```sql theme={null}
approx_top_k(N[, reserved])(column)
```

**别名**: `approx_top_count`

**参数**

* `N` — 要返回的元素个数。默认值：`10`。`N` 的最大值为 `65536`。[`UInt64`](/zh/reference/data-types/int-uint)
* `reserved` — 可选。定义为值预留的单元数量。如果 `uniq(column) > reserved`，则结果将为近似值。默认值：`N * 3`。[`UInt64`](/zh/reference/data-types/int-uint)

**参数**

* `column` — 要查找最常见值的列名。[`String`](/zh/reference/data-types/string)

**返回值**

返回一个数组，其中包含近似最常见的值及其出现次数，并按近似频率降序排序。[`Array`](/zh/reference/data-types/array)

**示例**

**使用示例**

```sql title=Query theme={null}
SELECT approx_top_k(2)(k)
FROM VALUES('k Char, w UInt64', ('y', 1), ('y', 1), ('x', 5), ('y', 1), ('z', 10));
```

```response title=Response theme={null}
┌─approx_top_k(2)(k)────┐
│ [('y',3,0),('x',1,0)] │
└───────────────────────┘
```

**另请参阅**

* [topK](/zh/reference/functions/aggregate-functions/topK)
* [topKWeighted](/zh/reference/functions/aggregate-functions/topKWeighted)
* [approx\_top\_sum](/zh/reference/functions/aggregate-functions/approxtopsum)
