GROUP_CONCAT 配合 group by 一起使用,用于将某一列的值按照指定的分割符进行拼接,MySQL 默认的分隔符为都好。语法如下:
group concat([distinct] column_name [order by column_name asc/desc] [separator '分隔符'])
例如:
select dept, count(*) ,group_concat(name) from employee group by dept;
select dept, count(*) ,group_concat(name order by name desc) from employee group by dept;
select dept, count(*) ,group_concat(name order by name desc,separator ':') from employee group by dept;