SUM
函数说明
SUM() 聚合函数用于计算一组值的和(NULL 值被忽略)。
函数语法
1. > SUM(expr)
参数释义
| 参数 | 说明 |
|---|---|
| expr | 任何数值类型与字符串列的列名 |
返回值
返回 expr 列的数值的和,若输入参数为 Double 类型,则返回值为 Double,否则为整数类型。
如果没有匹配的行,则返回 NULL 值。
示例
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 sum(col_1c) from tbl1;
11. +-------------+
12. | sum(col_1c) |
13. +-------------+
14. | 21 |
15. +-------------+
17. > select sum(col_1d) as c1 from tbl1 where col_1d < 13 group by col_1e order by c1;
18. +------+
19. | c1 |
20. +------+
21. | 8 |
22. | 10 |
23. | 18 |
24. | 21 |
25. +------+
