VIN码唯一,力洋ID多。 多行变1行
SELECT A.[VIN码], B.[力洋ID] FROM
(
SELECT [VIN码], [力洋ID] = CONVERT(xml,'<root><v>' + REPLACE([力洋ID], ';', '</v><v>') + '</v></root>') FROM [tbl_VINdecode]
) A OUTER APPLY
(
SELECT [力洋ID] = N.v.value('.', 'varchar(100)') FROM A.[力洋ID].nodes('/root/v') N(v)
) B
--多行合并为一行
R语言
方法一
https://stackoverflow.com/questions/22756372/collapse-text-by-group-in-data-frame
aggregate(df$text, list(df$group), paste, collapse="")
## Group.1 x
## 1 a a1a2a3
## 2 b b1b2
## 3 c c1c2c3
From <https://stackoverflow.com/questions/22756372/collapse-text-by-group-in-data-frame>
方法二
library(plyr)
ddply(df, .(group), summarize, text=paste(text, collapse=""))
## group text
## 1 a a1a2a3
## 2 b b1b2
## 3 c c1c2c3
From <https://stackoverflow.com/questions/22756372/collapse-text-by-group-in-data-frame>
网友评论