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

stddev_samp

Function

The stddev_samp function is used to return the sample standard deviation of the specified column.

Syntax

stddev_samp(col)

Parameters

Parameter

Mandatory

Description

col

Yes

A column with numeric data type. Other types return NULL.

Return Values

Returns a value of type DOUBLE.

Examples

  • Calculate the sample standard deviation of all items inventory. Example command:
    select stddev_samp(items) from warehouse; 

    Result:

    +------------+
    | _c0        |
    +------------+
    | 1.342355   |
    +------------+
  • Used with GROUP BY to group all items by warehouse (warehouseId) and calculate the sample standard deviation of items inventory within the same group. Example command:
    select warehouseId, stddev_samp(items) from warehouse group by warehouseId; 

    Result:

    +------------+------------+
    | warehouseId| _c1        |
    +------------+------------+
    | city1    | 1.23124   |
    | city2    | 1.23344   |
    | city3    | 1.43425   |
    +------------+------------+