Aggregate
BigQuery
VAR_SAMP
Menghitung variance (ragam) sampel dari nilai numerik. Menggunakan formula pembagi N-1 (Bessel's correction), cocok untuk data sampel.
Tipe hasil:
FLOAT64Diperbarui: 7 Jan 2026Syntax
SQL
VAR_SAMP(expression)Parameter
expressionnumericwajib
Kolom atau ekspresi numerik yang akan dihitung variance sampelnya
Contoh Penggunaan
Sample Variance untuk Survey Data
SQL
1 SELECT 2 survey_wave, 3 AVG(satisfaction_score) as avg_satisfaction, 4 VAR_SAMP(satisfaction_score) as variance, 5 STDDEV_SAMP(satisfaction_score) as stddev, 6 COUNT(*) as sample_size 7 FROM `project.dataset.customer_survey` 8 GROUP BY survey_wave 9 ORDER BY survey_wave;
Menganalisis variance satisfaction score per wave survei.
Hasil
| survey_wave | avg_satisfaction | variance | stddev | sample_size |
|---|---|---|---|---|
| 2024-Q1 | 4.2 | 0.85 | 0.92 | 1500 |
| 2024-Q2 | 4.5 | 0.72 | 0.85 | 1620 |
F-Test Preparation
SQL
1 SELECT 2 'Group A' as group_name, 3 VAR_SAMP(value) as variance, 4 COUNT(*) as n 5 FROM `project.dataset.experiment_a` 6 UNION ALL 7 SELECT 8 'Group B' as group_name, 9 VAR_SAMP(value) as variance, 10 COUNT(*) as n 11 FROM `project.dataset.experiment_b`;
Menyiapkan data untuk F-test (membandingkan variance).
Hasil
| group_name | variance | n |
|---|---|---|
| Group A | 125.5 | 50 |
| Group B | 98.2 | 48 |
Pooled Variance Calculation
SQL
1 SELECT 2 SUM((n - 1) * var_samp) / SUM(n - 1) as pooled_variance 3 FROM ( 4 SELECT 5 treatment_group, 6 VAR_SAMP(outcome) as var_samp, 7 COUNT(*) as n 8 FROM `project.dataset.clinical_trial` 9 GROUP BY treatment_group 10 );
Menghitung pooled variance untuk combined analysis.
Hasil
| pooled_variance |
|---|
| 45.8 |
Coefficient of Variation
SQL
1 SELECT 2 product_id, 3 AVG(daily_sales) as mean_sales, 4 SQRT(VAR_SAMP(daily_sales)) as sales_stddev, 5 SQRT(VAR_SAMP(daily_sales)) / AVG(daily_sales) * 100 as cv_percent 6 FROM `project.dataset.daily_product_sales` 7 GROUP BY product_id 8 HAVING COUNT(*) >= 30 9 ORDER BY cv_percent DESC 10 LIMIT 10;
Menghitung coefficient of variation untuk volatility analysis.
Hasil
| product_id | mean_sales | sales_stddev | cv_percent |
|---|---|---|---|
| P001 | 150 | 75 | 50.0 |
| P002 | 320 | 128 | 40.0 |
| P003 | 500 | 100 | 20.0 |