> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-8c05c8a2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 计算总体方差。

# varPop

<h2 id="varPop">
  varPop
</h2>

引入版本：v1.1.0

计算总体方差。

总体方差的计算公式如下：

$$
\frac{\Sigma{(x - \bar{x})^2}}{n}
$$

<br />

其中：

* $x$ 为总体中的每个值
* $\bar{x}$ 为总体均值
* $n$ 为总体大小

<Note>
  该函数使用数值不稳定的算法。如果计算中需要[数值稳定性](https://en.wikipedia.org/wiki/Numerical_stability)，请改用 [`varPopStable`](/reference/functions/aggregate-functions/varPopStable) 函数。该函数速度较慢，但计算误差更小。
</Note>

**语法**

```sql theme={null}
varPop(x)
```

**别名**：`VAR_POP`

**参数**

* `x` — 待计算总体方差的数据总体。[`(U)Int*`](/reference/data-types/int-uint) 或 [`Float*`](/reference/data-types/float) 或 [`Decimal*`](/reference/data-types/decimal)

**返回值**

返回 `x` 的总体方差。[`Float64`](/reference/data-types/float)

**示例**

**计算总体方差**

```sql title=Query theme={null}
DROP TABLE IF EXISTS test_data;
CREATE TABLE test_data
(
    x UInt8,
)
ENGINE = Memory;

INSERT INTO test_data VALUES (3), (3), (3), (4), (4), (5), (5), (7), (11), (15);

SELECT
    varPop(x) AS var_pop
FROM test_data;
```

```response title=Response theme={null}
┌─var_pop─┐
│    14.4 │
└─────────┘
```
