AVG

Description

Aggregate function.

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

Syntax

  1. > AVG(expr)

Arguments

ArgumentsDescription
exprAny 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");
  9. > select avg(col_1c) from tbl1;
  10. +-------------+
  11. | avg(col_1c) |
  12. +-------------+
  13. | 3.5000 |
  14. +-------------+
  15. > select sum(col_1d) as s1,avg(col_1d) as a3 from tbl1 group by col_1e order by s1 desc;
  16. +------+---------+
  17. | s1 | a3 |
  18. +------+---------+
  19. | 21 | 10.5000 |
  20. | 18 | 9.0000 |
  21. | 10 | 10.0000 |
  22. | 8 | 8.0000 |
  23. +------+---------+
  24. > select avg(col_1d) as a1 from tbl1 where col_1d < 13 group by col_1e order by a1;
  25. +---------+
  26. | a1 |
  27. +---------+
  28. | 8.0000 |
  29. | 9.0000 |
  30. | 10.0000 |
  31. | 10.5000 |
  32. +---------+

Constraints

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