比如我有一条sql语句执行结果是select * from tableA
id name value
1  张三  笔
2  李四  墨
3  陈武  纸
4  张三  砚
5  李四  琴棋
6  陈武  书画怎样才能得到结果select * from tableA
id name value
1  张三  笔,砚
2  李四  墨,琴棋
3  陈武  纸,书画请求如何编写?谢谢大家 

解决方案 »

  1.   

    select [name ],[Value]=stuff((select ','+[Value] from tableA   where T.Student=Student for xml path('')),1,1,'')
     from Class  T  group by tableA
      

  2.   

    select [Name ],[Value]=stuff((select ','+[Value] from tableA   where T.[Name]=[Name] for xml path('')),1,1,'')
     from Class  T  group by tableA
      

  3.   

    能解释一下 xml path是干什么用的吗?
    还有请教 如果用临时表能实现吗