答案 0 :(得分:0)
在SQL Server 2008中这很棘手-您应该更新软件!它已经寿终正寝了。
该方法使用XML:
select s.style,
stuff( (select ',' + convert(varchar(255), curr)
from (select t.*,
row_number() over (partition by t.style order by (select null)) as rowid
from t
) t cross apply
(values (GPB, 1), (EUR, 2), (USD, 3), (AUD, 4)
) v(curr, ord)
where t.style = s.style
order by rowid, ord
for xml path ('')
), 1, 1, '') as currencies
from (select distinct style from t) s;
order by
将同一行中的所有值保持在一起,并按列对值进行排序。
答案 1 :(得分:0)
SELECT
t1.Style,
ProductIDs = STUFF((
SELECT ', ' + t2.ProductIDs
FROM TableName t2
WHERE t1.Style= t2.Style
FOR XML PATH('')
),1, 2, '')
FROM TableName t1
GROUP BY t1.Style