SQL COVAR_POP function
Population covariance of two columns: divides by n over the complete pairs.
- Categoría
- Aggregates
- Returns
numeric- In this category
- 27 of 52
Sintaxis
COVAR_POP(y, x) | COVAR_POP(y, x) OVER (...)
Soporte del motor
| Motor | Support | Notas |
|---|---|---|
| SQL Server | Not built in | same manual formula |
| PostgreSQL | Sí | Supported under this name. |
| MySQL | Not built in | compute manually: AVG(y*x) - AVG(y)*AVG(x) |
| SQLite | Not built in | No built-in equivalent. |
| Oracle | Sí | Supported under this name. |
Ejemplos
PostgreSQL
SELECT covar_pop(height, weight) FROM people;
Oracle
SELECT COVAR_POP(salary, age) FROM employees;
Conviene saberlo
- Complete pairs only: either input NULL drops the row from the computation.
- One complete pair returns 0 (divisor n), not NULL like COVAR_SAMP.
- It is the building block of Pearson correlation: CORR(y,x) = COVAR_POP(y,x) / (STDDEV_POP(y) * STDDEV_POP(x)).
Questions about COVAR_POP
COVAR_POP vs COVAR_SAMP?
Divisor n versus n-1, and the one-pair result: 0 versus NULL.
Does MySQL have COVAR_POP?
No, but AVG(y*x) - AVG(y)*AVG(x) is exactly it over complete pairs.
How does CORR use it?
CORR is COVAR_POP normalized by both population standard deviations.
Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.
Related on SQLly
Cheat sheets for the engines that have it: PostgreSQL, Oracle.
Functions your engine actually has
SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.