Name

COVAR_SAMP

Synopsis

The COVAR_SAMP function returns the sample covariance of a set of dependent and independent variables.

SQL2003 Syntax

Call the function with two variables, one dependent and the other independent:

COVAR_SAMP( dependent, independent )

The function disregards any pair in which either the dependent variable, independent variable, or both are NULL. The result of the function is NULL when none of the input pairs consist of two non-NULL values.

Oracle

Oracle supports the SQL2003 syntax and implements the following analytic syntax:

COVAR_SAMP ( dependent, independent ) OVER (window_clause)

For an explanation of the window_clause, see the section later in this chapter titled Section 4.3.

DB2, MySQL, PostgreSQL, and SQL Server

These platforms do not support any form of the COVAR_SAMP function.

Example

The following COVAR_SAMP example uses the data shown by the first SELECT:

SELECT * FROM test2;
         Y          X
---------- ----------
         1          3
         2          2
         3          1
SQL> SELECT COVAR_SAMP(y,x) FROM test2;
COVAR_SAMP(Y,X)
---------------
             -1

Get SQL in a Nutshell, 2nd 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.