Skip to main content
Aggregate · Window
Aliases: variance NULL values are ignored. Fewer than two non-NULL values yields NULL.

Syntax

A window function keeps each input row and adds a result for that row. PARTITION BY groups rows with matching values; without it, all input rows form one group.

Aggregate

Window

Arguments

Aggregate and window

Returns

  • Type: DOUBLE
  • NULL behavior: NULL values are ignored. Fewer than two non-NULL values yields NULL.
  • Empty input: Returns NULL on empty input.

Properties

Usage notes

  • Returns DOUBLE. Sample statistics divide by n − 1; population statistics divide by n, where n is the number of included values.
  • INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
  • DISTINCT removes duplicates in grouped aggregation. Do not use it to remove duplicates in a window call.

Examples

Sample variance

The squared distances from the mean are 4, 0 and 4. Dividing their sum by 3 − 1 gives a sample variance of 4.

Groups with different numbers of values

NULL values are excluded from the calculation. Results are rounded to six decimal places where needed.

Limitations

  • DISTINCT removes duplicates in grouped calls.
  • The result is DOUBLE. Query tools may report the input’s floating-point or decimal type, but that does not change the returned value’s type.
  • DISTINCT in a window call currently has no effect: duplicate rows still contribute to the result. Use grouped DISTINCT aggregation when duplicate removal is required.
Last modified on October 15, 2026