日期:2014-05-18 浏览次数:20506 次
select name ,produce=stuff((select ','+produce from table1 where name=T.name),1,1,'') from table1 T group by name
------解决方案--------------------
select min(id) id, name,
[produce] = stuff((select ',' + [produce] from tb t where name = tb.name for xml path('')) , 1 , 1 , '')
from tb
group by name
------解决方案--------------------
SELECT id,name,
produce= STUFF
(
(SELECT DISTINCT ',' + 物料名称
from table1 b where b.id=c.id for xml path('')) , 1 , 1 , ''
) from table1 a
------解决方案--------------------
;with t
as
(
select name,stuff(select ','+produce
from tb
where name=a.name for xml path(''))produce
from tb a
group by name
)
select row_number() over(order by name) id,*
from t
------解决方案--------------------
SELECT id,name,
produce= STUFF
(
(SELECT DISTINCT ',' + produce
from table1 b where b.id=c.id for xml path('')) , 1 , 1 , ''
) from table1 a group by id,name
------解决方案--------------------