Categories:

Aggregate Functions (General) , Window Functions

VAR_POP

Returns the population variance of non-NULL records in a group. If all records inside a group are NULL, a NULL is returned.

Aliases:

VARIANCE_POP

Syntax

VAR_POP( [DISTINCT] x )

Arguments

expr

The expr should evaluate to one of the numeric data types.

Returns

The data type of the returned value is NUMBER(<precision>, <scale>). The scale depends upon the values being processed.

Examples

This example shows how to use the VAR_POP function:

Create and fill a table:

create table aggr(k int, v decimal(10,2), v2 decimal(10, 2));
insert into aggr values 
   (1, 10, null),
   (2, 10, 11), 
   (2, 20, 22), 
   (2, 25, null), 
   (2, 30, 35);

Query the table, calling VAR_POP():

SELECT k, var_pop(v), var_pop(v2) 
    FROM aggr 
    GROUP BY k;
+---+---------------+---------------+
| K |    VAR_POP(V) |   VAR_POP(V2) |
|---+---------------+---------------|
| 1 |  0.0000000000 |          NULL |
| 2 | 54.6875000000 | 96.2222222222 |
+---+---------------+---------------+