码迷,mamicode.com
首页 > 数据库 > 详细

【MySQL】MySQL的group_concat使用例子

时间:2016-01-14 22:21:18      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

> 参考的优秀文章

GROUP_CONCAT(expr)

 

> 简单的例子

此函数的功能,是拼接group分组多行的数据为一行,并可以指定去重、排序、分隔符。

 

例子:

技术分享
select t.name, group_concat(distinct t.role order by t.sort asc separator ;) from 
(
select Nick as name, coder as role, 1 as sort
union all
select Nick as name, admin as role, 3 as sort
union all
select Nick as name, admin as role, 2 as sort
union all
select Viki as name, coder as role, 1 as sort
union all
select Viki as name, admin as role, 2 as sort
union all
select Viki as name, player as role, 3 as sort
union all
select Darren as name, admin as role, 2 as sort
union all
select Darren as name, player as role, 1 as sort
) t 
group by t.name;
View Code

 

结果:

技术分享

【MySQL】MySQL的group_concat使用例子

标签:

原文地址:http://www.cnblogs.com/nick-huang/p/5131664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!