7.22.10 VAR_SAMP
VAR_SAMP determines the variance of a sample.
- Organization of this subsection
(1) Specification format
general-set-function-VAR_SAMP ::= VAR_SAMP(value-expression)
(2) Explanation of specification format
- value-expression:
-
Specifies the input values, in the form of a value expression, that make up the sample whose variance is to be determined. For details about value expressions, see 7.20 Value expression.
(3) Rules
-
Null values are not included in the calculation.
-
In the following cases, the execution result will be a null value.
-
If the number of input rows is 0 or 1
-
If the values to be calculated are all null values
-
-
Letting N be the number of input lines, S1 the sum of the input values, and S2 the sum of the values obtained by squaring the input values, the result of the general set function VAR_SAMP is calculated as follows:
(S2 - S1 × S1 ÷ N) ÷ (N - 1)
-
The following table shows the data type that can be specified in the value expression and the data type of the execution result of the general set function VAR_SAMP.
Table 7‒23: Data type that can be specified in the value expression and data type of the execution result of the general set function VAR_SAMP No.
Data type that can be specified in the value expression
Data type of the execution result of general set function VAR_SAMP
1
INTEGER
DOUBLE PRECISION
2
SMALLINT
3
DECIMAL(m,n)
4
DOUBLE PRECISION
(4) Example
- Example
-
Using the data in the salary table (SALARYLIST), this example determines the variance of a sample of employee salaries (SALARY) by job class (POSITION).
SELECT "POSITION",VAR_SAMP("SALARY") AS "VAR_SAMP" FROM "SALARYLIST" GROUP BY "POSITION" ORDER BY "POSITION"
Example of execution results