Name
COVAR_POP
The COVAR_POP function returns the population covariance of a set of dependent and independent variables.
ANSI SQL Standard Syntax
Call the function with two variables, one dependent and the other independent:
COVAR_POP(dependent
,independent
)
The function disregards any pair in which either the dependent variable, the independent variable, or both are NULL. If no rows remain in the group after NULL elimination, the result of the function is NULL.
Oracle
Oracle supports the ANSI SQL syntax and implements the following analytic syntax:
COVAR_POP(dependent
,independent
) OVER (window_clause
)
For an explanation of the window_clause
, see the section later in this chapter titled “ANSI SQL Window Functions.”
PostgreSQL
PostgreSQL supports the ANSI SQL syntax of the COVAR_POP function.
MySQL and SQL Server
These platforms do not support any form of the COVAR_POP function.
Example
The following COVAR_POP example uses the data retrieved by the first SELECT:
SELECT * FROM test2;
Y X ---------- ---------- 1 3 2 2 3 1SELECT COVAR_POP(y,x) FROM test2;
COVAR_POP(Y,X) -------------- -.66666667
Get SQL in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.