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 precisionfor 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_POPfor population variance. - Cast the input to
double precisionto get adouble precisionresult.
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;