Skip to content

STDDEV_SAMP and STDDEV_POP

Given a set of integer, decimal, or floating-point numbers, return the sample standard deviation or the population standard deviation. The STDDEV_SAMP function returns a result that is equivalent to the square root of the sample variance of the same set of values.

STDDEV_SAMP | STDDEV (expression)
STDDEV_POP (expression)

The expression must be an integer, decimal, or floating-point number. The return type is either DOUBLE PRECISION (for floating-point inputs) or DECIMAL (for all other inputs).

STDDEV_SAMP and STDDEV are synonyms.

For example:

premdb=# select avg(avg_att), stddev_samp(avg_att) stddevsamp, stddev_pop(avg_att) stddevpop 
from team where avg_att>0;
  avg   |    stddevsamp    |    stddevpop     
--------+------------------+------------------
 36.461 | 15.0809117098404 | 14.6990544934019
(1 row)

In this example, the standard deviation results are rounded:

premdb=# select avg(avg_att), round(stddev_samp(avg_att)) stddevsamp, round(stddev_pop(avg_att)) stddevpop 
from team where avg_att>0;
  avg   | stddevsamp | stddevpop 
--------+------------+-----------
 36.461 |         15 |        15
(1 row)

Note: The STDDEV or STDDEV_SAMP function for an expression that consists of a single value returns NULL. The STDDEV_POP function for an expression that consists of a single value returns 0).

Parent topic:Aggregate Functions