我有

ID username group
1  philip   football
2  george   baseball
3  alice    football
4  ani      football
5  george   football


并试图做到这一点

username   group
philip     football
george     baseball, football
alice      football
ani        football


换句话说,我想将意识形态组合成一个字符串,例如“ baysboll,football”

最佳答案

您需要GROUP_CONCAT函数

 select username, GROUP_CONCAT(group) FROM table GROUP BY Username

10-07 12:01