STDDEV_SAMP
Returns the sample standard deviation of the expression values in a group of rows.
PostgreSQL 17.5
STDDEV_SAMP(expression)Parameters
- expressionnumeric | double precision
- Numeric expression
Return value
A number: numeric for integers and numeric, double precision for floating-point numbers; NULLs are ignored; NULL if there are fewer than two values
Examples
Sample and population deviation
PostgreSQL 17.5
SELECT STDDEV_SAMP(x) AS sample_stddev,
STDDEV_POP(x) AS population_stddev
FROM (
VALUES (2),
(4),
(4),
(4),
(5),
(5),
(7),
(9)
) AS t(x);Average price and its spread
PostgreSQL 17.5
SELECT family_member,
ROUND(AVG(unit_price), 1) AS avg_price,
ROUND(STDDEV_SAMP(unit_price), 1) AS price_stddev
FROM Payments
GROUP BY family_member
ORDER BY family_member;Details
It is the square root of VAR_SAMP. STDDEV is a synonym for STDDEV_SAMP, and STDDEV_POP computes the population deviation: it divides by n, not by n − 1.