VARIANCE [Aggregate]
Evaluates the sample variance for each row of the group. This is defined as the sum of squares of the difference of expression from the mean of expression divided by the number of remaining rows minus 1.
(SUM(expression*expression) - SUM(expression) *SUM(expression) /COUNT(expression)) / (COUNT(expression) -1)
Behavior Type
Syntax
VARIANCE ( expression )
Parameters
expression |
Any |
Related Functions
The nonstandard function VARIANCE
is provided for compatibility with other databases. It is semantically identical to VAR_SAMP
.
This aggregate function differs from analytic function VARIANCE
, which computes the sample variance of the current row with respect to the group of rows within a window.
Examples
The following example returns the sample variance for each household ID in the customer
table.
=> SELECT VARIANCE(household_id) FROM customer_dimension; variance ------------------ 74848598.0106764 (1 row)