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

# COVAR_SAMP

> Returns the sample covariance.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Aggregate · Window</span></div>

Pairs with either value NULL are excluded. Fewer than two valid pairs yields NULL.

## Syntax

A window function keeps each input row and adds a result for that row. `PARTITION BY` groups rows with matching values; without it, all input rows form one group.

### Aggregate

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
covar_samp(y, x)
```

### Window

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
covar_samp(y, x) OVER ([PARTITION BY key] [ORDER BY ordering_key] [ROWS frame])
```

* Use a frame that includes all rows in the group or starts at the first row (`UNBOUNDED PRECEDING`). Sliding frames that drop earlier rows are not supported. RANGE frames with a numeric or time offset are not supported.

## Arguments

### Aggregate and window

| Name | Type | Required | Description |
| - | - | - | - |
| y | TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE or DECIMAL(p, s) | Yes | First member of the pair. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |
| x | TINYINT, SMALLINT, INTEGER, BIGINT, FLOAT, DOUBLE or DECIMAL(p, s) | Yes | Second member of the pair. For DECIMAL(p, s), p is precision (total digits) and s is scale (digits after the decimal point). |

## Returns

* Type: DOUBLE
* NULL behavior: Pairs with either value NULL are excluded. Fewer than two valid pairs yields NULL.
* Empty input: Returns NULL on empty input.

## Properties

| Property | Value |
| - | - |
| Deterministic | Partial (Floating-point results can differ slightly because of rounding.) |
| Supports DISTINCT | No |
| Supports window usage | Partial (Use all rows in the group or start at its first row. Sliding frames and RANGE offsets are not supported.) |
| Supports window frames | Partial (Use all rows in the group or start at its first row. Sliding frames and RANGE offsets are not supported.) |
| Exact result | Partial (Floating-point arithmetic can round.) |

## Usage notes

* Inputs are converted to DOUBLE. Floating-point rounding can cause small differences in the last digits of the result.
* INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
* Supports DISTINCT: Adding DISTINCT does not remove duplicate input values.

## Examples

### Basic example

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH t(y,x) AS (VALUES (0.0,0.0),(2.0,2.0)) SELECT covar_samp(y,x) AS result FROM t;
```

| result |
| - |
| 2.0 |

### A negative relationship and a missing pair

The row with a NULL value is excluded from the calculation.

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
WITH sample(x, y) AS (VALUES (1, 3), (3, 1), (CAST(NULL AS INT), 100))
SELECT covar_samp(CAST(x AS DOUBLE), CAST(y AS DOUBLE)) AS result FROM sample;
```

| result |
| - |
| -2 |

## Limitations

* Use all rows in the group or a frame starting with UNBOUNDED PRECEDING. Other starting boundaries are outside the forms covered here.
* DISTINCT does not remove duplicate input values in grouped calls. Removing duplicates can change the result, so remove duplicates from the input separately when needed.


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