Reference > Aggregate Methods
avg(value)
Definition
Double avg(Number value)
Description
Average of all non-null values.
Parameter Definition
Name |
Type |
Description |
value |
Number |
value to take average of. |
Example 1
| CREATE TABLE input(symbol String, price double);
INSERT INTO input VALUES ("MSFT",100),("MSFT",null),("MSFT",200);
INSERT INTO input VALUES ("AAPL",300),("AAPL",450);
Table result = SELECT symbol, avg(price) as avg FROM input GROUP BY symbol;
Table input = SELECT * FROM input;
// input =
// +-------------+
// | input |
// +------+------+
// |symbol|price |
// |String|Double|
// +------+------+
// |MSFT |100.0 |
// |MSFT !null |
// |MSFT |200.0 |
// |AAPL |300.0 |
// |AAPL |450.0 |
// +------+------+
//
// result =
// +-------------+
// | input |
// +------+------+
// |symbol|avg |
// |String|Double|
// +------+------+
// |MSFT |150.0 |
// |AAPL |375.0 |
// +------+------+
//
|
Note that the null value was avoided here