> 参考的优秀文章
> 简单的例子
此函数的功能,是拼接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;
结果:
时间: 2024-10-20 01:38:12