我的表中的数据如下:
Author ID Book Name A1 Book1 A1 Book2 A2 Book4 A2 Book5
我想将数据表示为
A1 Book1,Book2 A2 Book3,Book5
如果不使用临时表,我该怎么做?
答案 0 :(得分:0)
这个问题已经被提问并回答了。在发布之前检查问题。
根据您的专栏编辑此代码。
Select T1.Id
, Stuff(
(
Select ', ' + T2.Address
From MyTable As T2
Where T2.Id = T1.Id
Order By T2.Address
For Xml Path(''), type
).value('.', 'nvarchar(max)'), 1, 2, '') As Address
From MyTable As T1
Group By T1.Id