[英]Combining rows in mysql
I have data like: 我有类似的数据:
ID Code1 Procedures1 Code2 Procedure2
001 1 a, b, c NA NA
001 NA NA 2 x, y, z
And i would like it to look like this: 我希望它看起来像这样:
ID Code1 Procedures1 Code2 Procedure2
001 1 a, b, c 2 x, y, z
I tried different versions of concat as well as groupings and it didnt seem to work. 我尝试了不同版本的concat和分组,但似乎没有用。
Thanks for the help! 谢谢您的帮助!
try this 尝试这个
Update MyTable a
(inner join select * from MyTable) b on a.ID=b.ID
set a.Code1=case when a.Code1 is not null then Code1 else Code2 end,
a.Procedures1=case when a.Procedures1 is not null then a.Procedures1 else b.Procedures2 end,
a.Code2=case when a.Code2 is not null then a.Code2 else b.Code2 end,
a.Procedures2 =case when a.Procedures2 is not null then a.Procedures2 else b.Procedures2 end
and after that remove the duplicated of just running 然后删除刚刚运行的重复项
select distinct * from My_Table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.