我有
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
换句话说,我想把grop idetms组合成一个字符串,就像这里的“baysboll,football”
答案 0 :(得分:3)
您需要GROUP_CONCAT
功能
select username, GROUP_CONCAT(group) FROM table GROUP BY Username
答案 1 :(得分:3)
Group
以避免语法错误。 GROUP
是 Reserved Keyword 。
SELECT username, GROUP_CONCAT(`group`)
FROM table
GROUP BY userName