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

> 指定した カラム内で、おおよそ出現頻度の高い値の配列を返します。返される配列は、値そのものではなく、各値のおおよその出現頻度の高い順にソートされます。さらに、値の重みも考慮されます。

# topKWeighted

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

導入バージョン: v1.1.0

指定されたカラム内で、おおよそ出現頻度が最も高い値の配列を返します。
返される配列は、値そのものではなく、値のおおよその出現頻度の降順でソートされます。
さらに、値の重みも考慮されます。

**関連項目**

* [topK](/ja/reference/functions/aggregate-functions/topK)
* [approx\_top\_k](/ja/reference/functions/aggregate-functions/approxtopk)
* [approx\_top\_sum](/ja/reference/functions/aggregate-functions/approxtopsum)

**構文**

```sql theme={null}
topKWeighted(N)(column, weight)
topKWeighted(N, load_factor)(column, weight)
topKWeighted(N, load_factor, 'counts')(column, weight)
```

**パラメータ**

* `N` — 返す要素数。デフォルト値: 10。[`UInt64`](/ja/reference/data-types/int-uint)
* `load_factor` — 省略可。値のために予約するセル数を指定します。`uniq(column) > N * load_factor` の場合、topK 関数の結果は近似値になります。デフォルト値: 3。[`UInt64`](/ja/reference/data-types/int-uint)
* `counts` — 省略可。結果に近似カウントと誤差の値を含めるかどうかを指定します。[`Bool`](/ja/reference/data-types/boolean)

**引数**

* `column` — 最も頻出する値を見つける対象のカラム名。- `weight` — 重み。頻度の計算では、各値は `weight` 回出現したものとしてカウントされます。[`UInt64`](/ja/reference/data-types/int-uint)

**戻り値**

重みの近似合計が最大となる値の配列を返します。[`Array`](/ja/reference/data-types/array)

**例**

**使用例**

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

```response title=Response theme={null}
┌─topKWeighted(2)(k, w)──┐
│ ['z','x']              │
└────────────────────────┘
```

**counts パラメータを指定する場合**

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

```response title=Response theme={null}
┌─topKWeighted(2, 10, 'counts')(k, w)─┐
│ [('z',10,0),('x',5,0)]              │
└─────────────────────────────────────┘
```

**関連項目**

* [topK](/ja/reference/functions/aggregate-functions/topK)
* [approx\_top\_k](/ja/reference/functions/aggregate-functions/approxtopk)
* [approx\_top\_sum](/ja/reference/functions/aggregate-functions/approxtopsum)
