# varSamp (/docs/reference/sql/aggregate-functions/varsamp)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

Calculate the sample variance of a data set.

The sample variance is calculated using the formula:

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

<br />

Where:

* $x$ is each individual data point in the data set
* $\bar\{x}$ is the arithmetic mean of the data set
* $n$ is the number of data points in the data set

The function assumes that the input data set represents a sample from a larger population. If you want to calculate the variance of the entire population (when you have the complete data set), you should use [`varPop`](/reference/functions/aggregate-functions/varPop) instead.

:::note
This function uses a numerically unstable algorithm. If you need [numerical stability](https://en.wikipedia.org/wiki/Numerical_stability) in calculations, use the [`varSampStable`](/reference/functions/aggregate-functions/varSampStable) function. It works slower but provides a lower computational error.
:::

**Syntax**

```sql
varSamp(x)
```

**Arguments**

* `x` — The population for which you want to calculate the sample variance. [`(U)Int*`](/reference/data-types/int-uint) or [`Float*`](/reference/data-types/float) or [`Decimal*`](/reference/data-types/decimal)

**Returned value**

Returns the sample variance of the input data set `x`. [`Float64`](/reference/data-types/float)

**Examples**

**Computing sample variance**

```sql title=Query
DROP TABLE IF EXISTS test_data;
CREATE TABLE test_data
(
    x Float64
)
ENGINE = Memory;

INSERT INTO test_data VALUES (10.5), (12.3), (9.8), (11.2), (10.7);

SELECT round(varSamp(x),3) AS var_samp FROM test_data;
```

```text title=Response
┌─var_samp─┐
│    0.865 │
└──────────┘
```

*Introduced in version 1.1.0.*
