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 | 



VAR_SAMP Function

Description

The VAR_SAMP function returns the sample variance. The denominator is the number of all rows - 1. Only one expression is specified as a parameter. If the DISTINCT or UNIQUE keyword is included, it calculates the sample variance after deleting the duplicates, and if the keyword is omitted or is ALL, it calculates the sample variance for all values.

The return value is a DOUBLE type. If there are no rows that can be used for calculating a result, NULL will be returned.

The following are the formulas applied to the function.

VAR_POP = { 1 / (N-1) } * SUM( { xI - AVG(x) }2 )

  • SUM : Sum
  • AVG : Average

VAR_SAMP( [ DISTINCT | UNIQUE | ALL] expression )

  • expression : Specifies one expression to return the numeric.
  • ALL : Is used to calculate the sample variance of unique values without duplicates. It is the default value.
  • DISTINCT or UNIQUE : Is used to calculate the sample variance 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 VAR_SAMP(d) FROM test_table;

               var_samp(d)

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

    6.867768094172856e+03

 

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

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

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

        4.647855218839577e+08

 

TRUNCATE TABLE test_table;

SELECT VAR_SAMP(d) FROM test_table;

                var_samp(d)

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

                      NULL