立即学习:https://edu.csdn.net/course/play/27328/370699?utm_source=blogtoedu
gruop_concat:将某一列的值按指定的分隔符进行拼接
group_concat([distinct]column_name [order by column_name asc/desc][separator'分隔符'])
例:
select dept, group_concat(name) from employee group by dept;
+-------+-----------------------------------+
| dept | group_concat(name) |
+-------+-----------------------------------+
| 部门A | 张三,李小梅,李芳,张江,马小龙,柳峰 |
| 部门B | 李四,王五,龙五,马小花 |
| 部门C | 李洁,欧阳辉,冯小芳 |
+-------+-----------------------------------+
按名字降序:
select dept, group_concat(name order by name desc) from employee group by dept;
分号间隔:select dept, group_concat(name order by name desc separator ';') from employee group by dept;