比如说有一个表:
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=数量
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 数量2
100 50 1 0
180 100 1 0
200 90 1 0
100 70 1 0