简体   繁体   English

将多行合并为一列

[英]Merge multiple rows into one column

I'm trying to merge different old values in one single column. 我正在尝试将不同的旧值合并到一个列中。 I have this table 我有这张桌子

id  code    langtype    desc        duration            
232 1104466 1           IT text     10
233 1104466 2           EN text     10
234 1104466 6           other desc  10
235 1104466 1           Other IT text(different row) 10
236 1104466 2           Other EN text(same row of previous) 10

And i would like to obtain a result like this 我想获得这样的结果

id  code    desc                                                duration
232 1104466 “IT” = “IT TEXT”, EN=”EN TEXT”, “ES”=”Other desc”   10

It is possibile is mysql? 可能是mysql吗?

Thank you 谢谢

Yes, it is possible. 对的,这是可能的。 Something like this should achieve this effect: 这样的事情应该可以达到这种效果:

select group_concat(concat(langtype, ' = ', desc))
from table
group by code

Here we first form a value to be extracted from each row ( concat(langtype, ' = ', desc) ) and then concatenate it for each grouped row ( group_concat ). 在这里,我们首先形成一个要从每一行提取的值( concat(langtype, ' = ', desc) ),然后将其串联到每个分组行( group_concat )。 You can change delimiters, or add quotes where you need - look at GROUP_CONCAT and CONCAT docs. 您可以更改定界符,或在需要的地方添加引号-查看GROUP_CONCATCONCAT文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM