メインコンテンツへスキップ

uniqExact

導入バージョン: v1.1.0 異なる引数値の正確な個数を計算します。
uniqExact 関数は、uniq よりも多くのメモリを使用します。異なる値の数が増えるにつれて state のサイズが際限なく増大するためです。 正確な結果がどうしても必要な場合は、uniqExact 関数を使用してください。 それ以外の場合は、uniq 関数を使用してください。
構文
uniqExact(x[, ...])
引数 戻り値 異なる引数値の正確な個数を UInt64 として返します。UInt64 基本的な使い方
Query
CREATE TABLE example_data
(
    id UInt32,
    category String
)
ENGINE = Memory;

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

SELECT uniqExact(category) as exact_unique_categories
FROM example_data;
Response
┌─exact_unique_categories─┐
│                       3 │
└─────────────────────────┘
複数の引数
Query
SELECT uniqExact(id, category) as exact_unique_combinations
FROM example_data;
Response
┌─exact_unique_combinations─┐
│                         6 │
└───────────────────────────┘
関連項目
最終更新日 2026年6月10日