TB1:
订单号   数量
1        10
2        5
3        8要求结果:
1   2   3
10  5   8应该怎么写?

解决方案 »

  1.   

    为什么我
    select case when 订单号=1 then 数量 end,case when 订单号=2 then 数量 end,case when 订单号=3 then 数量 end from tb1为什么出来的结果是这样的:
    10    null  null
    null  8     null
    null  null  5
    而不是
    10    8    5
      

  2.   

    select max(case when 订单号=1 then 数量 end),
    max(case when 订单号=2 then 数量 end),
    max(case when 订单号=3 then 数量 end) from tb1
      

  3.   

    select case 订单号 when 1 then 数量 when 2 then 数量 when 3 then 数量 end from tb1
      

  4.   

    嘿嘿 参考楼上的select max(case when id=1 then id end) as a,
    max(case when id=2 then id end) as b,
    max(case when id=3 then id end) as c into ##aa from tb1insert into ##aa select max(case when id=1 then amout end),
    max(case when id=2 then amout end),
    max(case when id=3 then amout end) from tb1select * from ##aa
    order by a