VAR_SAMP

<< Click to Display Table of Contents >>

Navigation:  Streaming SQL Reference Guide > Basic Building Blocks > Functions > Aggregate Functions > Statistical Variance and Deviation Functions >

VAR_SAMP

Previous pageReturn to chapter overviewNext page

Returns the sample variance of a non-null set of numbers (nulls being ignored),

VAR_SAMP ( [DISTINCT | ALL] number-expression )

 

where ALL includes (and DISTINCT excludes) duplicate values in the input set. ALL is the default. When the the input set has no non-null data, VAR_SAMP returns NULL.

VAR_SAMP uses the following calculation:

(SUM(expr*expr) - SUM(expr)*SUM(expr) / COUNT(expr)) / (COUNT(expr)-1)

In other words, for a given set of non-null values, using S1 as the sum of the values and S2 as the sum of the squares of the values, VAR_POP returns the result (S2-S1*S1/N)/(N-1).

You can use VAR_SAMP as either an aggregate and analytic function. Applied to an empty set, it returns null. Given an input set of one element, VAR_SAMP returns null.

See also population variance, VAR_POP, STDDEV_POP, and STDDEV_SAMP.