COVAR_SAMP

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the sample covariance between two sets of values.

Syntax 

1covar_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.

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

Covariance by Group 

Calculate covariance for each group.

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

Related Documentation