select (case when isnull(SUM(LH_HCK.lh_cl),0)=0 then 0 else isnull(SUM(LH_HCK.lh_fq),0)/isnull(SUM(LH_HCK.lh_cl),0)*1000000 end) as hck_bll from LH_HCK where "date"=convert(varchar(10),getdate()- 1,120)
这句单独查询时显示结果为97560
select (CASE WHEN ISNULL( SUM(LH_ZT.lh_cl),0)='0' THEN 0 ELSE isnull (SUM(LH_ZT.lh_fq),0)/isnull(SUM(LH_ZT.lh_cl),0)*1000000 END)as zt_bll,(case when isnull(SUM(LH_HCK.lh_cl),0)=0 then 0 else isnull(SUM(LH_HCK.lh_fq),0)/isnull(SUM(LH_HCK.lh_cl),0)*1000000 end) as hck_bll from LH_ZT join LH_HCK ON LH_ZT."date"=LH_HCK."date" WHERE LH_ZT."date"=convert(varchar(10),getdate()- 1,120) and LH_HCK."date"=convert(varchar(10),getdate()- 1,120)
链接另一张有空值的表后结果都是0,这是什么原因?求大神解释。
------解决方案--------------------
内联就是这样的结果,不会有null出现,你要有的话要用外联
------解决方案--------------------
你想不管LH_ZT 表有没有对用数据,但是LH_HCK 表都显示数据,用 LEFT OUTER JOIN
------解决方案--------------------
把第2句的join改为left join试试..