为什么我 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
select max(case when 订单号=1 then 数量 end), max(case when 订单号=2 then 数量 end), max(case when 订单号=3 then 数量 end) from tb1
select case 订单号 when 1 then 数量 when 2 then 数量 when 3 then 数量 end from tb1
嘿嘿 参考楼上的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
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
max(case when 订单号=2 then 数量 end),
max(case when 订单号=3 then 数量 end) from tb1
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