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 |
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.