VARIANCE [Analytic]
Returns the sample variance of a nonNULL
set of numbers (NULL
values in the set are ignored) for each row of the group within a window. Results are calculated as follows:
( SUM( expression * expression )  SUM( expression ) * SUM( expression ) / COUNT( expression )) / (COUNT( expression )  1 )
VARIANCE
returns the variance of expression, which is calculated as follows:
 0 if the number of rows in expression = 1
VAR_SAMP
if the number of rows in expression > 1
The nonstandard function VARIANCE
is provided for compatibility with other databases. It is semantically identical to VAR_SAMP
.
Behavior Type
Syntax
VAR_SAMP ( expression ) OVER ( [ windowpartitionclause ] [ windoworderclause ] [ windowframeclause ] )
Parameters
expression 
Any NUMERIC data type or any nonnumeric data type that can be implicitly converted to a numeric data type. The function returns the same data type as the numeric data type of the argument. 
OVER()

Examples
The following example calculates the cumulative variance in the store orders fact table of sales in December 2007:
=> SELECT date_ordered, VARIANCE(SUM(total_order_cost)) OVER (ORDER BY date_ordered) "variance" FROM store.store_orders_fact s WHERE date_ordered BETWEEN '20071201' AND '20071231' GROUP BY s.date_ordered; date_ordered  variance + 20071201  NaN 20071202  2259129762 20071203  1809012182.33301 20071204  35138165568.25 20071205  26644110029.3003 20071206  25943125234 20071207  23178202223.9048 20071208  21940268901.1431 20071209  21487676799.6108 20071210  21521358853.4331 (10 rows)