mysql高级聚合

GROUP_CONCAT()

函数的值等于属于一个组的指定列的所有值,以逗号隔开,并且以字符串表示

mysql> select sex,group_concat(level) from role group by sex;
+------+---------------------+
| sex  | group_concat(level) |
+------+---------------------+
|    0 | 8,4,91              |
|    1 | 10,20,20,29,60      |
+------+---------------------+
2 rows in set (0.00 sec)

with rollup子句:用来要求在一条group by子句中进行多个不同的分组

mysql> select sex,count(1) from role group by sex with rollup;
+------+----------+
| sex  | count(1) |
+------+----------+
|    0 |        3 |
|    1 |        5 |
| NULL |        8 |
+------+----------+
3 rows in set (0.00 sec)

猜你喜欢

转载自www.cnblogs.com/playforever/p/9336820.html
今日推荐