也许有很多表,他们之间以某个字段相关联,现在用一个表为例,
表t1
t_id tnum1 tnum2 tnum3 tnum4
1001 1 1 0 2
1002 0 0 2 0
1003 2 0 3 3
1004 5 5 0 0
在form中有listbox1,listbox2,edit1, listbox1用来显示表t1的所有字段名,
listbox2显示你在listbox1中所选择的字段名,下面我在edit1中写入sql语句,
语句包括计算列,例如:select (tnum1+tnum2)/tnum3,(tnum3+tnum4)/tnum2
from t1
实现的功能是:遇到除数为0的时候,相应的值为0,除数不为0,等于相应的值。
上面举例的查询结果应该得到:
0 2
0 0
0.667 0
0 0
请问:以上的功能如何实现?谢谢
表t1
t_id tnum1 tnum2 tnum3 tnum4
1001 1 1 0 2
1002 0 0 2 0
1003 2 0 3 3
1004 5 5 0 0
在form中有listbox1,listbox2,edit1, listbox1用来显示表t1的所有字段名,
listbox2显示你在listbox1中所选择的字段名,下面我在edit1中写入sql语句,
语句包括计算列,例如:select (tnum1+tnum2)/tnum3,(tnum3+tnum4)/tnum2
from t1
实现的功能是:遇到除数为0的时候,相应的值为0,除数不为0,等于相应的值。
上面举例的查询结果应该得到:
0 2
0 0
0.667 0
0 0
请问:以上的功能如何实现?谢谢
from t1
case when tnum3=0 then 0 else (tnum1+tnum2)/tnum3 end,
case when tnum2=0 then 0 else (tnum3+tnum4)/tnum2 end,
from t1
decode(tnum2,'','0',null,'0',(tnum3+tnum4)/tnum2)
from t1
写错了,多了个逗号 呵呵
case when tnum3=0 then 0 else (tnum1+tnum2)/tnum3 end,
case when tnum2=0 then 0 else (tnum3+tnum4)/tnum2 end,
from t1
就是说:你们所判断的tnum3=0或tnum2=0 那只不过是我写的固定字段名,
我的意思是:如果有很多关联表,我从这些表中随意选字段,然后对这些
字段进行除法操作,如果除数遇到0怎么办?