sql server 2005 A字段相同数据的B字段合并

 

如图,写出查询语句结果为

 

 

查询语句为:select
      difficultName ,
     (STUFF((select ';'+area FROM MoneyAndArea  WHERE difficultName=b.difficultName
     ORDER BY difficultName FOR XML PATH('')),1,1,'')) AS area,
     (STUFF((select ';'+[money] FROM MoneyAndArea  WHERE difficultName=b.difficultName
     ORDER BY difficultName FOR XML PATH('')),1,1,'')) AS [money]
from MoneyAndArea b
group by difficultName

posted on 2012-02-04 10:44  MyBeN  阅读(1929)  评论(0编辑  收藏  举报

导航