VARIANCE/VAR_SAMP

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the sample variance of input values.

Syntax 

1variance(<expression>)

Arguments 

Required 

  • <expression>: An expression of any numerical type.

Returns 

  • NUMERIC(38,6) for integer-type or numeric arguments.
  • double precision for floating-point arguments.

Returns NULL if the computation is meaningless.

Considerations 

  • Uses N-1 in the denominator (Bessel’s correction).
  • Variance is the square of the standard deviation.
  • Use VAR_POP for population variance.
  • Cast the input to double precision to get a double precision result.

Examples 

Calculate Variance 

Find the variance of prices.

1SELECT variance(price) AS price_variance
2FROM products;

Variance by Group 

Calculate variance for each category.

1SELECT category, variance(price) AS price_variance
2FROM products
3GROUP BY category;

Related Documentation