ClickHouse/docs/zh/sql-reference/aggregate-functions/reference/topkweighted.md
2022-08-26 15:07:59 -04:00

44 lines
945 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
slug: /zh/sql-reference/aggregate-functions/reference/topkweighted
sidebar_position: 109
---
# topKWeighted {#topkweighted}
类似于 `topK` 但需要一个整数类型的附加参数 - `weight`。 每个输入都被记入 `weight` 次频率计算。
**语法**
``` sql
topKWeighted(N)(x, weight)
```
**参数**
- `N` — 要返回的元素数。
**参数**
- `x` (要计算频次的)值。
- `weight` — 权重。 [UInt8](../../../sql-reference/data-types/int-uint.md)类型。
**返回值**
返回具有最大近似权重总和的值数组。
**示例**
查询:
``` sql
SELECT topKWeighted(10)(number, number) FROM numbers(1000)
```
结果:
``` text
┌─topKWeighted(10)(number, number)──────────┐
│ [999,998,997,996,995,994,993,992,991,990] │
└───────────────────────────────────────────┘
```