mysql group_concat函数详解
函数语法:
group_concat( [DISTINCT] 要连接的字段 [Order BY 排序字段 ASC/DESC] [Separator ‘分隔符’] )
先看我测试表的总数据信息:
select * from employee
1.将同一个部门的人合并到一起。
select dept_id,group_concat(name) from employee group by dept_id
2. 换一种分隔符
select dept_id,group_concat(name separator ";") from employee group by dept_id
3.将工资按照部门然后去重
select dept_id,group_concat(distinct salary separator ";") from employee group by dept_id
3.将同个部门的工资按照倒序排(去重)。
select dept_id,group_concat(distinct salary order by salary desc) from employee group by dept_id