VAR_SAMP
Returns the sample variance of the expression values in a group of rows.
PostgreSQL 17.5
VAR_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 variance
PostgreSQL 17.5
SELECT VAR_SAMP(x) AS sample_variance,
VAR_POP(x) AS population_variance
FROM (
VALUES (2),
(4),
(4),
(4),
(5),
(5),
(7),
(9)
) AS t(x);Price spread for family members
PostgreSQL 17.5
SELECT family_member,
COUNT(*) AS payments,
ROUND(VAR_SAMP(unit_price), 1) AS price_variance
FROM Payments
GROUP BY family_member
ORDER BY family_member;Details
The sample variance divides the sum of squared deviations from the mean by n − 1, and the population variance VAR_POP by n. VARIANCE is a synonym for VAR_SAMP.