Updated on 2026-11-06 GMT+08:00

variance/var_pop

Function

The variance/var_pop function is used to return the population variance of a column.

Syntax

variance(col), 
var_pop(col)

Parameters

Parameter

Mandatory

Description

col

Yes

A column with numeric data type. Columns of other types return NULL.

Return Values

Returns a value of type DOUBLE.

Examples

  • Calculate the variance of all items inventory. Example command:
    select variance(items) from warehouse; 
    -- Equivalent to the following statement.
    select var_pop(items) from warehouse;

    Result:

    _c0        
    203.42352 
  • Used with GROUP BY to group all items by warehouse (warehouseId) and calculate the variance of items inventory within the same group. Example command:
    select warehouseId, variance(items) from warehouse group by warehouseId; 
    -- Equivalent to the following statement.
    select warehouseId, var_pop(items) from warehouse group by warehouseId;

    Result:

    warehouseId _c1        
    city1    19.23124   
    city2    17.23344   
    city3    12.43425