variance_ samp
On this page
Returns the sample variance of non-NULL values.
Syntax
variance_samp(<expr>)Arguments
| Argument | Type | Description |
|---|---|---|
<expr> | int, uint, or float | Input value. |
Returns
Returns float. Ignores NULL values. Returns NULL when fewer than two non-NULL values are available.
Examples
Estimate how much request latency varies across channels from a sample of requests:
VALUES
('web', 100.0), ('web', 120.0), ('web', 140.0),
('mobile', 60.0), ('mobile', 120.0), ('mobile', 180.0)
SELECT $0 AS channel, $1 AS latency_ms
GROUP BY channel
AGGREGATE avg(latency_ms) AS avg_ms, variance_samp(latency_ms) AS variance_ms2
ORDER BY channel+---------+--------+--------------+
| channel | avg_ms | variance_ms2 |
+---------+--------+--------------+
| mobile | 120.0 | 3600.0 |
| web | 120.0 | 400.0 |
+---------+--------+--------------+Both channels average 120 ms, but mobile durations vary more. The sample variance is measured in ms².