VAR_POP

Calculate population variance. This function computes the statistical variance for a set of values assumed to be the entire population.

Syntax

VAR_POP(expr)

Description

Returns the population standard variance of expr. It considers rows as the whole population, not as a sample, so it has the number of rows as the denominator. You can also use VARIANCE(), which is equivalent but is not standard SQL.

Variance is calculated by

  • working out the mean for the set;

  • for each number, subtracting the mean and squaring the result;

  • calculating the average of the resulting differences.

It is an aggregate function, and so can be used with the GROUP BY clause.

VAR_POP() can be used as a window function.

VAR_POP() returns NULL if there were no matching rows.

Examples

CREATE TABLE v(i tinyint);

INSERT INTO v VALUES(101),(99);

SELECT VAR_POP(i) FROM v;
+------------+
| VAR_POP(i) |
+------------+
|     1.0000 |
+------------+

INSERT INTO v VALUES(120),(80);

SELECT VAR_POP(i) FROM v;
+------------+
| VAR_POP(i) |
+------------+
|   200.5000 |
+------------+

As an aggregate function:

As a window function:

See Also

This page is licensed: GPLv2, originally from fill_help_tables.sql

Last updated

Was this helpful?