VARIANCE function [Aggregate]

Function

Returns the variance of a set of numbers.

Syntax

VARIANCE ( [ ALL ] expression )

Parameters

expression Any numeric data type (float, real, or double precision) expression.

Examples

Given this data:

SELECT salary FROM employee WHERE dept_id = 300

      salary

 51432.000

 57090.000

 42300.000

   43700.00

  36500.000

138948.000

  31200.000

    58930.00

    75400.00

The following statement returns the value 1063923790.99999994.

SELECT VARIANCE ( salary ) FROM employee
WHERE dept_id = 300

Given this data:

SELECT unit_price FROM product WHERE name = 'Tee Shirt'

name

unit_price

Tee Shirt

            9.00

Tee Shirt

          14.00

Tee Shirt

          14.00

The following statement returns the value 8.33333333333334327.

SELECT VARIANCE ( unit_price ) FROM product
WHERE name = 'Tee Shirt'

Usage

The formula used to calculate VARIANCE is

The formula used by the VARIANCE function to calculate variance is var equals n times the sum of x squared minus (the sum of x) squared divided by n times (n minus one).

VARIANCE returns a result of data type double precision floating point. If applied to the empty set, the result is NULL.

VARIANCE does not support the keyword DISTINCT. A syntax error is returned if DISTINCT is used with VARIANCE.

Standards and compatibility

See also

“STDDEV function [Aggregate]”