日期:2014-05-17 浏览次数:20496 次
select distinct,
styleid,
stuff((select ','+CAST(colorid as varchar)
from tb t2
where t1.styleid = t2.styleid
group by colorid
For xml path('')
),1,1,'') as colorid,
stuff((select ','+sizeid
from tb t2
where t1.styleid = t2.styleid
group by sizeid
For xml path('')
),1,1,'') as sizeid
from tb t1
--drop table tb
--go
create table tb(styleid varchar(20),colorid varchar(10),sizeid varchar(10))
insert into tb
select 'AA125094', '82', 'L'
union all select 'AA125094', '82' ,'M'
union all select 'AA125094', '82' ,'S'
union all select 'AA125094', '82' ,'XL'
union all select 'AA125094', 'E5' ,'L'
union all select 'AA125094', 'E5' ,'M'
union all select 'AA125094', 'E5' ,'S'
union all select 'AA125094', 'E5' ,'XL'
union all select 'AA125601', '71' ,'L'
union all select 'AA125601', '71' ,'M'
union all select 'AA125601', '71' ,'S'
union all select 'AA125601', '77' ,'L'
union all select 'AA125601', '77' ,'M'
union all se