例如表1
字段: id zc zj gl
表2
字段: id lx zf df
表3
字段: id gb gbje
公式 (表1.zc+表2.lx+表2.df)/gb
gb首先提取表3.gb,若表3.bg为空值或者为0,则提取表3.gbje.最后将结果显示到edit中
字段: id zc zj gl
表2
字段: id lx zf df
表3
字段: id gb gbje
公式 (表1.zc+表2.lx+表2.df)/gb
gb首先提取表3.gb,若表3.bg为空值或者为0,则提取表3.gbje.最后将结果显示到edit中
from t1,t2,t3 where t1.id=t2.id and t1.id = t3.id
create table t1(id int, zc int, zj int, gl int);
create table t2(id int, lx int, zf int, df int);
create table t3(id int, gb int, gbje int);
insert into t1 values(1,1,1,1);
insert into t2 values(1,2,2,2);
insert into t3 values(1,2,0);
insert into t1 values(2,1,1,1);
insert into t2 values(2,2,2,2);
insert into t3 values(2,0,3);
--执行查询
select (t1.zc+t2.lx+t2.df)/(case when t3.gb is null or t3.gb=0 then t3.gbje else t3.gb end) rst
from t1,t2,t3 where t1.id=t2.id and t1.id = t3.id
--查询结果
Rst
2.5
1.66666666666667