日期:2014-05-17 浏览次数:20620 次
create table #tab(PID varchar(50),PName varchar(50), PAmount int, PAddress varchar(50))
insert into #tab
select 'aaa1', '张三', 10000, '四川省' union all
select 'aaa1', '李四', 20000, '四川省' union all
select 'aaa1', '王五', 30000, '四川省'
select ROW_NUMBER()over(order by PID)id,PID,
(select stuff((
select ','+PName from #tab for xml path('')),1,1,''))PName,
sum(PAmount)PAmount,
PAddress
from #tab
group by PID,PAddress
---------------------------------------------------------------------
id PID PName PA