Aggregate · Window
Aliases: stddev
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.
Stddev samp aggregate
Stddev samp window
Arguments
Stddev samp aggregate, stddev samp 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 is not supported for STDDEV or STDDEV_SAMP.
Examples
Sample standard deviation
The values have mean 3 and sample variance 4, so the sample standard deviation is 2.
Groups with different numbers of values
NULL values are excluded from the calculation. Results are rounded to six decimal places where needed.
Limitations
- 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 is not supported for STDDEV or STDDEV_SAMP.
Last modified on October 15, 2026