看个这个SQL语句该怎么写?请教高手
select name,Num as 库存量,(select sum(num) from outlibdan as o where o.productID=s.ProductID ) as 出库数量 ,(select sum(num) from inlibdan as i where i.productID=s.productID) as 入库数量
from doc_Products as s
left join libs on libs.productID=s.productID
我想加两列,一列是用入库数量-出库数量-库存量,一列是如果前一列那个值结果为0,则平衡,不为0则不平衡
我用,(select sum(num) from inlibdan as i where i.productID=s.productID)-,(select sum(num) from outlibdan as o where o.productID=s.ProductID ) -Num后倒是能到过结果,但是如果出库数量,或其它两个中有一个为null计算的结果就会是NULL,这怎么解决呢?