AVG

Description

Aggregate function.

The AVG() function calculates the average value of the argument.

Syntax

1. > AVG(expr)

Arguments

Arguments Description
expr Any numerical expression

Returned Value

The arithmetic mean, always as Double.

NaN if the input parameter is empty.

Examples

1. > drop table if exists tbl1,tbl2;
2. > create table tbl1 (col_1a tinyint, col_1b smallint, col_1c int, col_1d bigint, col_1e char(10) not null);
3. > insert into tbl1 values (0,1,1,7,"a");
4. > insert into tbl1 values (0,1,2,8,"b");
5. > insert into tbl1 values (0,1,3,9,"c");
6. > insert into tbl1 values (0,1,4,10,"D");
7. > insert into tbl1 values (0,1,5,11,"a");
8. > insert into tbl1 values (0,1,6,12,"c");

10. > select avg(col_1c) from tbl1;
11. +-------------+
12. | avg(col_1c) |
13. +-------------+
14. |      3.5000 |
15. +-------------+

17. > select sum(col_1d) as s1,avg(col_1d) as a3 from tbl1 group by col_1e order by s1 desc;
18. +------+---------+
19. | s1   | a3      |
20. +------+---------+
21. |   21 | 10.5000 |
22. |   18 |  9.0000 |
23. |   10 | 10.0000 |
24. |    8 |  8.0000 |
25. +------+---------+

27. > select avg(col_1d) as a1 from tbl1 where col_1d < 13 group by col_1e order by a1;
28. +---------+
29. | a1      |
30. +---------+
31. |  8.0000 |
32. |  9.0000 |
33. | 10.0000 |
34. | 10.5000 |
35. +---------+

Constraints

Currently, MatrixOne doesn’t support select function() without from tables.