# `COVAR_SAMP`

**Applies to:** ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the sample covariance between two sets of values.

## Syntax

```sql
covar_samp(<Y>, <X>)
```

## Arguments

### Required

- `<Y>`: A `double precision` expression.
- `<X>`: A `double precision` expression.

## Returns

Returns a `double precision` value representing the sample covariance. Returns NULL if the computation is meaningless.

## Considerations

- Returns NULL if there are fewer than two rows where both X and Y are non-null.
- Sample covariance uses N-1 in the denominator (Bessel's correction).
- Use `COVAR_POP` for population covariance.

## Examples

### Calculate Sample Covariance

Find the sample covariance between two variables.

```sql
SELECT covar_samp(test_score, study_hours) AS covariance
FROM student_data;
```

### Covariance by Group

Calculate covariance for each group.

```sql
SELECT department, covar_samp(performance, experience) AS perf_exp_cov
FROM employees
GROUP BY department;
```

## Related Documentation

- [COVAR_POP](/docs/data/data-cloud-query-guide/references/dc-sql-reference/covar-pop.md)
- [CORR](/docs/data/data-cloud-query-guide/references/dc-sql-reference/corr.md)
- [Aggregate Functions](/docs/data/data-cloud-query-guide/references/dc-sql-reference/aggregate.md)
