`
jackleechina
  • 浏览: 571563 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类

sql 多行并一行

    博客分类:
  • sql
 
阅读更多
1)
select _size from clothes where measurementNo='M11-031-M1' for xml path('')  

2)
select ','+_size from clothes where measurementNo='M11-031-M1' for xml path('')

3)去掉逗号
select  stuff((select ','+_size from clothes where measurementNo='M11-031-M1' for xml path('')),1,1,'')


4)
SELECT measurementNo,
       sizes= stuff(
       (SELECT '/'+_size
        FROM clothes c1 //c1不能少
         WHERE  measurementNo=c2.measurementNo
          FOR xml path('')
       ),1,1,'')
FROM   clothes c2
group by measurementNo


参考:http://blog.csdn.net/dobear_0922/article/details/2313839
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics