[英]How to combine rows into one with same column value in mysql
I have a table like this: 我有一张这样的桌子:
id value
1 a
1 b
2 c
2 d
2 e
I want to combine rows with the same ids into one,here is what i want as result: 我想将具有相同ID的行合并为一个,这就是我想要的结果:
id value
1 a b
2 c d e
try this 尝试这个
select id,group_concat(value) as value from tb_name group by id;
if you want space instead ',' then try below query 如果要用空格代替“,”,请尝试以下查询
select id,replace(group_concat(value), ',' ,' ') as value from tb_name group by id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.