メインコンテンツまでスキップ
バージョン: 4.x

COVAR_SAMP

説明

2つの数値変数間の標本共分散を計算します。

構文

COVAR_SAMP(<expr1>, <expr2>)

パラメータ

パラメータ説明
<expr1>数値式または列
<expr2>数値式または列

戻り値

expr1とexpr2の標本共分散を返します。特殊なケース:

  • expr1またはexpr2の列がNULLの場合、その行のデータは最終結果にカウントされません。

-- setup
create table baseall(
id int,
x double,
y double
) distributed by hash(id) buckets 1
properties ("replication_num"="1");

insert into baseall values
(1, 1.0, 2.0),
(2, 2.0, 3.0),
(3, 3.0, 4.0),
(4, 4.0, NULL),
(5, NULL, 5.0);
select covar_samp(x,y) from baseall;
+---------------------+
| covar_samp(x, y) |
+---------------------+
| 0.89442719099991586 |
+---------------------+