STDDEV or STDDEV_SAMP

The STDDEV or STDDEV_SAMP function returns the standard deviation (/n), or the sample standard deviation (/n-1), of a set of numbers.

Read syntax diagram
                     .-ALL------.                       
>>-+-STDDEV------+-(-+----------+-numeric-expression)----------><
   '-STDDEV_SAMP-'   '-DISTINCT-'                       

The schema is SYSIBM.

The function returns the biased standard deviation (/n) or the sample standard deviation (/n-1) of a set of numbers, depending on which keyword is specified:
STDDEV
The formula that is used to calculate the biased standard deviation is logically equivalent to:
STDDEV = SQRT(VAR)
STDDEV_SAMP
The formula that is used to calculate the sample standard deviation is logically equivalent to:
STDDEV = SQRT(VARIANCE_SAMP)

The argument values must each be the value of any built-in numeric data type, and their sum must be within the range of the data type of the result.

Start of changeThe arguments can also be a character string or graphic string data type. The string input is implicitly cast to a numeric value of DECFLOAT(34).End of change

If the argument is DECFLOAT(n), the result of the function is DECFLOAT(34). Otherwise, the result of the function is double precision floating-point. The result can be null.

Before the function is applied to the set of values derived from the argument values, null values are eliminated. If DISTINCT is specified, redundant duplicate values are also eliminated.

If the function is applied to an empty set, the result is the null value. Otherwise, the result is the standard deviation of the values in the set.

The order in which the values are aggregated is undefined, but every intermediate result must be within the range of the result data type.

STDDEV_POP can be specified as a synonym for STDDEV.

Example: Using sample table DSN8A10.EMP, set the host variable DEV, which is defined as double precision floating-point, to the standard deviation of the salaries for the employees in department 'A00' (WORKDEPT='A00').
   SELECT STDDEV(SALARY)
     INTO :DEV
     FROM DSN8A10.EMP
     WHERE WORKDEPT = 'A00';
For this example, host variable DEV is set to a double precision float-pointing number with an approximate value of '9742.43'.