比如说有一个表:
create table aaa(吊牌价 int,销售金额 int,数量 int)
insert into aaa select 100,50,1 union all
select 180,100,1 union all
select 200,90,1 union all
select 100,70,1select * from aaa  结果:
吊牌价  销售金额  数量
100 50 1
180 100 1
200 90 1
100 70 1我现在想得到这样的结果:
吊牌价  销售金额  数量1  数量2
100 50 1       0
180 100 0       1 
200 90 1       0 
100 70 0       1
即是当销售金额/吊牌价<=0.50时,数量1=数量,数量2=0,
当销售金额/吊牌价>0.50时,数量1=0,数量2=数量

解决方案 »

  1.   

    select 吊牌价,销售金额 , 数量1 = (case when 销售金额/吊牌价 <= 0.5 then 数量 else 0 end),数量2= (case when 销售金额/吊牌价 > 0.5 then 数量 else 0 end) from aaa
      

  2.   

    To: yrwx001()  你的结果不对呀,
    运行好得到这个的结果:
    吊牌价  销售金额  数量1  数量2
    100 50 1 0
    180 100 1 0
    200 90 1 0
    100 70 1 0
      

  3.   

    select 吊牌价,销售金额 , 数量1 = (case when cast(销售金额 as float)/cast(吊牌价 as float) <= 0.5 then 数量 else 0 end),数量2= (case when cast(销售金额 as float)/cast(吊牌价 as float) > 0.5 then 数量 else 0 end) from aaa
      

  4.   

    To:  yrwx001()  非常感谢你了!我的问题解决了.