COVAR_SAMP (Lakehouse v1)
集計関数です。
covar_samp() 関数は、2 つのデータ列の標本共分散(Σ((x - x̅)(y - y̅)) / (n - 1))を返します。
Analyzeの構文
Section titled “Analyzeの構文”func.covar_samp(<expr1>, <expr2>)Analyzeの例
Section titled “Analyzeの例”func.covar_samp(table.items_sold, table.profit).alias('covar_samp_items_profit')
| covar_samp_items_profit ||-------------------------|| 250000.0 |SQLの構文
Section titled “SQLの構文”COVAR_SAMP(<expr1>, <expr2>)| 引数 | 説明 |
|---|---|
<expr1> |
任意の数値式 |
<expr2> |
任意の数値式 |
float64。n <= 1 の場合は +∞ を返します。
テーブルの作成とサンプルデータの挿入
CREATE TABLE store_sales ( id INT, store_id INT, items_sold INT, profit FLOAT);
INSERT INTO store_sales (id, store_id, items_sold, profit)VALUES (1, 1, 100, 1000), (2, 2, 200, 2000), (3, 3, 300, 3000), (4, 4, 400, 4000), (5, 5, 500, 5000);クエリのデモ: 販売数と利益の標本共分散を計算する
SELECT COVAR_SAMP(items_sold, profit) AS covar_samp_items_profitFROM store_sales;結果
| covar_samp_items_profit ||-------------------------|| 250000.0 |