Skip to content
SQLSimplified
aggregate

VARIANCE()

Returns the variance (squared spread) of a set of numeric values.

Description

VARIANCE is an aggregate function that measures how far a set of numbers spreads from their mean, squared. It's the square of the standard deviation and is widely used in statistics. A larger variance means the values are more dispersed.

Syntax

VARIANCE(expression)
VAR_SAMP(expression)
VAR_POP(expression)

Parameters

NameDescriptionOptional
expressionA numeric column or expression.No

Return Type

Returns a DOUBLE. With fewer than two non-NULL values it typically returns NULL.

Examples

Loading playground environment...
Loading playground environment...

Variance vs STDDEV

STDDEV is just the square root of VARIANCE. Use variance when you need the squared unit, or standard deviation for an interpretable, same-unit measure.

Common Mistakes

  • Mixing sample and population. VAR_SAMP vs VAR_POP differ slightly; VARIANCE usually means the sample form.
  • Interpreting the unit. Variance is in squared units, which can be hard to reason about. Prefer STDDEV for readability.
  • Non-numeric input. Variance requires numbers; text columns will error.

See also: AVG, STDDEV.

Cite this resource

SQLSimplified. "VARIANCE() SQL Function". Available at: https://sqlsimplified.online/reference/variance