COVAR_SAMP

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the sample covariance between two sets of values.

Syntax

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.

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

Covariance by Group

Calculate covariance for each group.

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

Related Documentation