如何做下面的查询(SELECT )

来源:百度知道 编辑:UC知道 时间:2024/05/07 07:57:28
例如:下面是表中的数据
CODE NAME PRICE BL FDPRICE
1001 AAA 100.00 0.02 0.00
1002 BBB 200.00 0.00 4.00

如何做出以下查询
CODE NAME PRICE BL FDPRICE
1001 AAA 100.00 0.02 2.00
1002 BBB 200.00 0.02 4.00
BL为0.00的时候,就要根据FDPRICE/PRICE得出其值;而FDPRICE为0.00的时候,就要根据PRICE * BL得出

你还是把你这道题的思路讲下吧!

是不是BL为0.00的时候,就要根据FDPRICE/PRICE得出其值;而FDPRICE为0.00的时候,就要根据PRICE * BL得出

????

用这个SQL function试一下了! decode

下面的链接有使用说明的例子:
http://www.adp-gmbh.ch/ora/sql/decode.html

SQL如下:

select t.code, t.name, t.price, decode(t.bl, 0, t.fdprice / t.price, t.bl) bl, decode(t.fdprice, 0, t.price * t.bl, t.fdprice) fdprice
from 表名 t

1)BL为0.00的时候,就要根据FDPRICE/PRICE得出其值;
select code,name,price,(FDPRICE/PRICE) as FP,FDPRICE from 你的表名 where BL=0.00

2)FDPRICE为0.00的时候,就要根据PRICE * BL得出
select code,name,price,bl,(price*bl) as PB from 你的表名 where FDPRICE=0.00

select code,name,price,bl,(price*bl) as fdprice
from tablename

1)BL为0.00的时候,就要根据FDPRICE/PRICE得出其值;
select code,name,price,(FDPRICE/PRICE) as FP,FDPRICE from 你的表名 where BL=0.00

2)FDPRICE为0.00的时候,就要根据PRICE * BL得出 <