Skip to Main Content
SQL in a Nutshell, 3rd Edition
book

SQL in a Nutshell, 3rd Edition

by Kevin Kline
November 2008
Intermediate to advanced content levelIntermediate to advanced
591 pages
17h 28m
English
O'Reilly Media, Inc.
Content preview from SQL in a Nutshell, 3rd Edition

Name

CORR

The CORR function returns the correlation coefficient between a set of dependent and independent variables.

ANSI SQL Standard Syntax

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

CORR(dependent, independent)

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

Oracle

Oracle supports the ANSI SQL syntax, and the following analytic syntax:

CORR(dependent, independent) OVER (window_ clause)

For an explanation of the window_clause, see the “ANSI SQL Window Functions” section later in this chapter.

PostgreSQL

PostgreSQL supports the ANSI SQL syntax of the CORR function.

MySQL and SQL Server

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

Example

The following CORR example uses the data retrieved by the first SELECT:

SELECT * FROM test2;
         Y          X
---------- ----------
         1          3
         2          2
         3          1

SELECT CORR(y,x) FROM test2;
CORR(Y,X)
---------
       −1
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Effective SQL: 61 Specific Ways to Write Better SQL, First Edition

Effective SQL: 61 Specific Ways to Write Better SQL, First Edition

John L. Viescas, Douglas J. Steele, Ben G. Clothier
SQL in a Nutshell, 4th Edition

SQL in a Nutshell, 4th Edition

Kevin Kline, Regina O. Obe, Leo S. Hsu

Publisher Resources

ISBN: 9780596155322Errata Page