AAA为float数据类型
UPDATE bs
SET AAA=case when (select count(zd) from bs WHERE bs.js is not null and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs)='0' then 0 else (select count(bsid) from bs WHERE bs.js >'0' and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs) end
FROM bs b    
结果正常
UPDATE bs
SET AAA=case when (select count(zd) from bs WHERE bs.js is not null and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs)='0' then 0 else (select count(zd) from bs WHERE bs.js is not null and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs) end
FROM bs b   
结果也正常
但是我把二个相除进数据库后结果不是0就是1,而不是二个相除的结果 如下:
UPDATE bs
SET AAA=case when (select count(zd) from bs WHERE bs.js is not null and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs)='0' then 0 else (select count(bsid) from bs WHERE bs.js >'0' and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs)/(select count(zd) from bs WHERE bs.js is not null and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs) end

解决方案 »

  1.   

    --try:
    UPDATE bs
    SET AAA=case when (select count(zd) from bs WHERE bs.js is not null and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs)='0' then 0 
    else 1.0*(select count(bsid) from bs WHERE bs.js >'0' and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs)/(select count(zd) from bs WHERE bs.js is not null and b.bstime > bs.bstime and b.zdid=bs.zdid and bs.sj >= b.sj-1 and b.bs = bs.bs) end