当前位置: 代码迷 >> Sql Server >> 求一条简略语句
  详细解决方案

求一条简略语句

热度:36   发布时间:2016-04-24 21:45:21.0
求一条简单语句
表是  GroupID CountryName
        1        中国
        1        美国
        1        德国
现在要的结果是 GroupID,CountryName 
                 1     中国、美国、德国

求好方法。。

------解决方案--------------------

select a.GroupID,
       stuff((select '、'+b.CountryName
              from [表名] b
              where b.GroupID=a.GroupID
              for xml path('')),1,1,'') 'CountryName'
 from [表名] a
 group by a.GroupID
  相关解决方案