id content
1 'aaa'
2 'bbb'
3 'ccc'
2 'ddd'
3 'eee'
按id分组 : select * from xxx group by id;
得到的结果可能是:
1 'aaa'
2 'bbb'
3 'ccc'
请问我如何修改能够得到如下结果:
1 'aaa'
2 'bbb ddd' //将id为2的所有content字符串连接起来
3 'ccc eee'//将id为3的所有content字符串连接起来
3 个解决方案
#1
select id,
group_concat(content)
from xxx
group by id;
from xxx
group by id;
#2
在MYSQL下用group_concat即可
select id,group_concat(content)
from tt group by id;
select id,group_concat(content)
from tt group by id;
#3
group_concat
#1
select id,
group_concat(content)
from xxx
group by id;
from xxx
group by id;
#2
在MYSQL下用group_concat即可
select id,group_concat(content)
from tt group by id;
select id,group_concat(content)
from tt group by id;
#3
group_concat