mysql常见聚合函数

count():总数量
avg():平均数
std():标准差
sum():求和
max():最大值
min():最小值

上面的不过多介绍
group_concat():分组列值全部展示到一行
eg:
mysql> desc Tgroup_concat;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(10) | YES | | NULL | |
| num | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+

mysql> select * from Tgroup_concat;
+------+------+
| name | num |
+------+------+
| zs | 1 |
| zs | 2 |
| ls | 4 |

mysql> select name,group_concat(num) from Tgroup_concat group by name;
+------+-------------------+
| name | group_concat(num) |
+------+-------------------+
| ls | 4 |
| zs | 1,2 |
+------+-------------------+
2 rows in set (0.00 sec)

 

mysql常见聚合函数

上一篇:第五章 数据库完整性


下一篇:Oracle--序列