VARIANCE() measures the average squared deviation from the mean across a population of values. It is equivalent to VAR_POP().
Run this SELECT query directly in MySQL or phpMyAdmin. It uses fixed inputs so you can verify the result without creating a table.
SELECT ROUND(VAR_POP(v), 2) AS population_variance FROM (SELECT 2 AS v UNION ALL SELECT 4 UNION ALL SELECT 6) AS sample;| population_variance |
|---|
| 2.67 |
VARIANCE() returns population variance and is a synonym for VAR_POP(). Use VAR_SAMP() when you need sample variance.
The examples use the student table SQL dump.
SELECT VARIANCE(mark), VAR_POP(mark), VAR_SAMP(mark)
FROM student;
| VARIANCE(mark) | VAR_POP(mark) | VAR_SAMP(mark) |
|---|---|---|
| 272.1728395061727 | 272.1728395061727 | 282.6410256410255 |
Use FORMAT() to control displayed decimal places.
SELECT FORMAT(VARIANCE(mark), 2)
FROM student;
| FORMAT(VARIANCE(mark), 2) |
|---|
| 272.17 |
VAR_SAMP() uses the sample denominator (n−1). Choose the function based on the statistical population represented.
Is VARIANCE() the same as VAR_SAMP()?
No. VARIANCE() means population variance in MySQL; VAR_SAMP() calculates sample variance.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.