STDDEV_POP

functionsupportedCore SQL functions

docs.snowflake.com ↗

Aggregate functionsWindow function syntax and usage

Returns the population standard deviation (square root of variance) of non-NULL values. See also STDDEV, which returns the sample standard deviation (square root of variance).

Syntax

supportedpartialnot supportednot scored

Aggregate function

STDDEV_POP( [ DISTINCT ] <expr1>)

Window function

STDDEV_POP( [ DISTINCT ] <expr1> ) OVER (
                                        [ PARTITION BY <expr2> ]
                                        [ ORDER BY <expr3> [ { ASC | DESC } ] [ NULLS { FIRST | LAST } ] [ <window_frame> ] ]
                                        )

Parameters

NameRequiredDescription
expr1requiredAn expression that evaluates to a numeric value. This is the expression on which the standard deviation is calculated.
expr2requiredThis is the optional expression to partition by.
expr3requiredThis is the optional expression to order by within each partition.

Returns

The data type of the returned value is DOUBLE. If all records inside a group are NULL, this function returns NULL.

Usage notes

Aggregate function examples

The following example calculates the standard deviation for a small population of integers: Note that the functions STDDEV and STDDEV_SAMP do not return the same result as STDDEV_POP. The following example assumes that you have a table named menu that lists food items for sale in a cafe. The following output shows the 6 rows in the table that belong to the Dessert category. Other rows also exist for other categories, such as Main and Beverage. To find the population standard deviation for the cost of goods sold and the sale price (for the Dessert rows only), run this query:

Window function example

The following example uses the same menu table but runs the STDDEV_POP function as a window function. The window function partitions rows by the item_category column. Therefore, the standard deviation is calculated once for each item category, and that value is repeated in the result for each row in the group. In this example, the rows must be grouped by both the item category and the cost of goods sold. (Note that the 6 Dessert rows are now grouped into 5 rows because two rows have the same cost of goods value.)

Referenced by