日期:2014-05-17 浏览次数:20739 次
SELECT s.IN1 - s.OUT +s.IN2
FROM
(
select sum(入库数量) AS IN1
from 表1
select sum(借出数量) AS OUT
from 表2
select sum(归还数量) AS IN2
from 表3
) s
SELECT 表1.productid,
SUM(ISNULL(表1.入库数量,0))-SUM(ISNULL(表2.借出数量,0))+SUM(ISNULL(表3.归还数量,0))
FROM 表1 LEFT JOIN
表2 ON 表1.productid=表2.productid LEFT JOIN
表3 ON 表1.productid=表3.productid
GROUP BY 表1.productid