Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

STDDEV_SAMP Function

Description

The STDDEV_SAMP function calculates the sample standard deviation. Only one expression is specified as a parameter. If the DISTINCT or UNIQUE keyword is inserted before the expression, it calculates the sample standard deviation after deleting duplicates; if a keyword is omitted or ALL, it calculates the sample standard deviation for all values.

The return value is the same as the square root of it's sample variance (VAR_SAMP Function) and it is a DOUBLE type. If there are no rows that can be used for calculating a result, NULL is returned.

The following are the formulas applied to the function.

STDDEV_SAMP = [ { 1 / (N-1) } * SUM( { xI - mean(x) }2 ) ]1/2

  • SUM: Sum
  • mean: Sample mean
Syntax

STDDEV_SAMP( [ { DISTINCT | DISTINCTROW } | UNIQUE | ALL] expression )

  • expression: An expression that returns a numeric value
  • ALL: Used to calculate the standard deviation for all values. It is the default value.
  • DISTINCT or UNIQUE: Used used to calculate the standard deviation for the unique values without duplicates.
Example

CREATE TABLE test_table (d DOUBLE);

INSERT INTO test_table VALUES(78), (63.65), (230.54), (32), (17.2), (195.7689), (57.57);

 

SELECT STDDEV_SAMP(d) FROM test_table;

            stddev_samp(d)

==========================

    8.287199825135663e+01

 

SELECT STDDEV_SAMP(POWER(d,2)+d*2+1) FROM test_table;

  stddev_samp( power(d, 2)+d*2+1)

=================================

           2.155888498702931e+04

 

TRUNCATE TABLE test_table;

SELECT STDDEV_SAMP(d) FROM test_table;

                stddev_samp(d)

==========================

                      NULL