标签:
此函数的功能,是拼接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;
结果:
标签:
原文地址:http://www.cnblogs.com/nick-huang/p/5131664.html