A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/functions/corr below:

Website Navigation


CORR | Snowflake Documentation

Categories:

Aggregate functions (General) , Window functions (General)

CORR

Returns the correlation coefficient for non-null pairs in a group. It is computed for non-null pairs using the following formula:

COVAR_POP(y, x) / (STDDEV_POP(x) * STDDEV_POP(y))

Where x is the independent variable and y is the dependent variable.

See also:

COVAR_POP , STDDEV_POP

Syntax

Syntax when used as an aggregate function:

Syntax when used as a window function:

CORR( y , x ) OVER ( [ PARTITION BY <expr3> ] )

Copy

Usage notes Examples
CREATE OR REPLACE TABLE aggr(k int, v decimal(10,2), v2 decimal(10, 2));
INSERT INTO aggr VALUES(1, 10, NULL);
INSERT INTO aggr VALUES(2, 10, 11), (2, 20, 22), (2, 25, NULL), (2, 30, 35);

SELECT * FROM aggr;

Copy

+---+-------+-------+
| K |     V |    V2 |
|---+-------+-------|
| 1 | 10.00 |  NULL |
| 2 | 10.00 | 11.00 |
| 2 | 20.00 | 22.00 |
| 2 | 25.00 |  NULL |
| 2 | 30.00 | 35.00 |
+---+-------+-------+
SELECT k, CORR(v, v2) FROM aggr GROUP BY k;

Copy

+---+--------------+
| K |  CORR(V, V2) |
|---+--------------|
| 1 |         NULL |
| 2 | 0.9988445981 |
+---+--------------+

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4