跳转到主内容
跳转到主内容

uniqExact

uniqExact

引入版本:v1.1

计算不同参数取值的精确数量。

注意

uniqExact 函数比 uniq 使用更多内存,因为随着不同值数量的增加,其状态大小会无限增长。 如果确实需要得到精确结果,请使用 uniqExact 函数。 否则请使用 uniq 函数。

语法

uniqExact(x[, ...])

参数

返回值

返回不同参数取值的精确计数,返回类型为 UInt64。UInt64

示例

基本用法

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;
┌─exact_unique_categories─┐
│                       3 │
└─────────────────────────┘

多参数

SELECT uniqExact(id, category) as exact_unique_combinations
FROM example_data;
┌─exact_unique_combinations─┐
│                         6 │
└───────────────────────────┘

另请参阅