VARIANCE/VAR_SAMP

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Computes the sample variance of input values.

Syntax

variance(<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.

SELECT variance(price) AS price_variance
FROM products;

Variance by Group

Calculate variance for each category.

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

Related Documentation