> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# covar_pop

> Returns the population covariance of two expressions.

Returns the population covariance of two expressions. This function is supported from v2.5.10. It can also be used as a window function.

## Syntax

```Haskell theme={null}
COVAR_POP(expr1, expr2)
```

## Parameters

`expr1` and `expr2` must evaluate to TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE, or DECIMAL.

If `expr1` and `expr2` are table columns, this function calculates the population covariance of these two columns.

## Return value

Returns a DOUBLE value. The formula is as follows, where `n` represents the row count of the table:

![covar\_pop formula](https://mintcdn.com/mirrorship-docs/8gpPdHU-sBXASb5i/documents/images/20588d5ebb4e5e05c683bd88.png?fit=max\&auto=format\&n=8gpPdHU-sBXASb5i\&q=85\&s=89fc0257dcdb067cf50e29fde8ff8f39)

## Usage notes

* A data row is counted only when the two columns in this row are non-null values. Otherwise, this data row is eliminated from the result.

* NULL is returned in any input is NULL.

## Examples

Suppose table `agg` has the following data:

```plaintext theme={null}
mysql> select * from agg;
+------+-------+-------+
| no   | k     | v     |
+------+-------+-------+
|    1 | 10.00 |  NULL |
|    2 | 10.00 | 11.00 |
|    2 | 20.00 | 22.00 |
|    2 | 25.00 |  NULL |
|    2 | 30.00 | 35.00 |
+------+-------+-------+
```

Calculate the population covariance of the `k` and `v` columns:

```plaintext theme={null}
mysql> select no,COVAR_POP(k,v) from agg group by no;
+------+-------------------+
| no   | covar_pop(k, v)   |
+------+-------------------+
|    1 |              NULL |
|    2 | 79.99999999999999 |
+------+-------------------+
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.