【MySQL】MySQL的group_concat使用例子
时间:2021-07-01 10:21:17
帮助过:2人阅读
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使用例子
标签: