# dcount()（聚合函数）dcount() (aggregation function)

`dcount()` 聚合函数主要用于估算大型集的基数。The `dcount()` aggregation function is primarily useful for estimating the cardinality of huge sets. 它以性能确定准确性，并可能在执行间返回不同的结果。It trades performance for accuracy, and may return a result that varies between executions. 输入的顺序可能会影响其输出。The order of inputs may have an effect on its output.

## 语法Syntax

... `|` `summarize` `dcount` `(``Expr` [, `Accuracy` ]`)` ...... `|` `summarize` `dcount` `(``Expr` [, `Accuracy` ]`)` ...

## 参数Arguments

• Expr：要对其非重复值进行计数的标量表达式。Expr : A scalar expression whose distinct values are to be counted.
• 准确度 ：一个可选的 `int` 文本，用于定义请求的估计准确度。Accuracy : An optional `int` literal that defines the requested estimation accuracy. 有关支持的值，请参阅下文。See below for supported values. 如果未指定，则使用默认值 `1`If unspecified, the default value `1` is used.

## 示例Example

``````PageViewLog | summarize countries=dcount(country) by continent
``````

``````T | summarize by V, G | summarize count() by G
``````

``````T | summarize dcount(B) by G | count
``````

## 估计准确度Estimation accuracy

`dcount()` 聚合函数使用 HyperLogLog (HLL) 算法的变体，该算法对集基数进行随机估算。The `dcount()` aggregate function uses a variant of the HyperLogLog (HLL) algorithm, which does a stochastic estimation of set cardinality. 该算法提供一个“旋钮”，可用于平衡每个内存大小的准确度和执行时间：The algorithm provides a "knob" that can be used to balance accuracy and execution time per memory size:

00 1.61.6 212212
11 0.80.8 214214
22 0.40.4 216216
33 0.280.28 217217
44 0.20.2 218218

“条目数”列是 HLL 实现中 1 字节计数器的数目。The "entry count" column is the number of 1-byte counters in the HLL implementation.

• 当准确度等级为 `1` 时，将返回 1000 个值When the accuracy level is `1`, 1000 values are returned
• 当准确度等级为 `2` 时，将返回 8000 个值When the accuracy level is `2`, 8000 values are returned