メインコンテンツまでスキップ
に最終更新

VAR_SAMP,VARIANCE_SAMP

説明​

VAR_SAMP 関数は指定した式の標本分散を計算します。VARIANCE(母分散)とは異なり、VAR_SAMP は n-1 を除数として使用します。標本分散は、統計学では母分散の不偏推定量とみなされます。

別名​

  • VARIANCE_SAMP

構文​

VAR_SAMP(<expr>)

パラメータ​

パラメータ説明
<expr>標本分散を計算する対象の列または式。DOUBLE 型をサポートします。

戻り値​

計算された標本分散を表す DOUBLE 型の値を返します。 グループ内に有効なデータがない場合は NULL を返します。

例​

-- Create sample table
CREATE TABLE student_scores (
student_id INT,
score DECIMAL(4,1)
) DISTRIBUTED BY HASH(student_id)
PROPERTIES (
"replication_num" = "1"
);

-- Insert test data
INSERT INTO student_scores VALUES
(1, 85.5),
(2, 92.0),
(3, 78.5),
(4, 88.0),
(5, 95.5),
(6, 82.0),
(7, 90.0),
(8, 87.5);

-- Calculate sample variance of student scores
SELECT
VAR_SAMP(score) as sample_variance,
VARIANCE(score) as population_variance
FROM student_scores;
+------------------+---------------------+
| sample_variance | population_variance |
+------------------+---------------------+
| 29.4107142857143 | 25.73437500000001 |
+------------------+---------------------+