热线电话:13121318867

登录
2020-10-31 阅读量: 769
mysql 中group_concat函数详解

函数语法:

group_concat( [DISTINCT] 要连接的字段 [Order BY 排序字段 ASC/DESC] [Separator ‘分隔符’] )

先看测试表的总数据信息:

select * from employee

image.png

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



0.0067
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子