avg
On this page
Returns the average of non-NULL values.
Syntax
avg(<expr>)Arguments
| Argument | Type | Description |
|---|---|---|
<expr> | int, uint, or float | Input value. |
Returns
Returns float. Returns NULL for empty input or when every value is NULL.
Examples
Compare average order values by store. Each row is a completed order, with its amount in US dollars:
VALUES
('north', 49.0), ('north', 79.0), ('north', 139.0),
('south', 29.0), ('south', 59.0)
SELECT $0 AS store, $1 AS order_usd
GROUP BY store
AGGREGATE count() AS orders, avg(order_usd) AS avg_order_usd
ORDER BY store+-------+--------+---------------+
| store | orders | avg_order_usd |
+-------+--------+---------------+
| north | 3 | 89.0 |
| south | 2 | 44.0 |
+-------+--------+---------------+