Hitachi

Hitachi Advanced Database SQL Reference


7.22.9 VAR_POP

VAR_POP determines the variance of a population.

Organization of this subsection

(1) Specification format

general-set-function-VAR_POP ::= VAR_POP(value-expression)

(2) Explanation of specification format

value-expression:

Specifies the input values, in the form of a value expression, that make up the population whose variance is to be determined. For details about value expressions, see 7.20 Value expression.

(3) Rules

  1. Null values are not included in the calculation.

  2. In the following cases, the execution result will be a null value.

    • If the number of input rows is 0

    • If the values to be calculated are all null values

  3. 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_POP is calculated as follows:

    (S2 - S1 × S1 ÷ N) ÷ N

  4. 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_POP.

    Table 7‒22: Data type that can be specified in the value expression and data type of the execution result of the general set function VAR_POP

    No.

    Data type that can be specified in the value expression

    Data type of the execution result of general set function VAR_POP

    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 population of employee salaries (SALARY) by job class (POSITION).

SELECT "POSITION",VAR_POP("SALARY") AS "VAR_POP"
    FROM "SALARYLIST"
    GROUP BY "POSITION"
    ORDER BY "POSITION"

Example of execution results

[Figure]