ID BODY
1 aaaa
2 bbbb
1 cccccc
3 ddddd
这样的数据
我要获取成
ID BODY
1 aaaa,ccccc
2 bbbb
3 ddddd
这样的,请高手说说思路和方法!
select distinct ID,STUFF((select ',' + body
from [追索]
where ID=a.ID
for xml path('')),1,1,'') as body
from [追索] a
刚随手写的 忘了加","号这下可以了
追索兄弟是对的,受教了。以下代码经过我检验是对的。
select distinct ID,STUFF((
select ','+BODY
from 【youtablename】
where ID=1
for xml path('')
),1,1,'')
as BODY
FROM 【youtablename】 a
select distinct _id ,(case when _id =(select distinct _id from Test_10 where _id=a._ID) then (select distinct case _id when 1 then 'aaaa,cccc' else _name end from Test_10 where _id=a._id) end) as '_name' from Test_10 a
写的有点牵强...经过测试 没问题(写的有点牵强的地方在于:when 1 then 'aaaa,cccc')