我有一个表用户
id firstname lastname
1 | Kenny | Kim
2 | Smith | Lt
3 | James | Wagh
4 | Wales | St
5 | Stephen | Mathew
团队表
tid manager teams
1 2 3
2 2 4
3 5 1
我想要结果
Manager Team Mates
Smith Lt James Wagh, Wales St, Kenny Kim
我没有得到如何加入。请注意。
答案 0 :(得分:1)
select concat(m.firstname, ' ', m.lastname) as Manager,
group_concat(concat(u.firstname, ' ', u.lastname) separator ', ') as `Team Mates`
from teams t
join user m on m.id = t.manager
join user u on u.id = t.teams
group by t.manager
答案 1 :(得分:-1)
在Mysql中学习连接,并尝试自己解决问题。以下链接可以为您提供很多帮助。