|
SELECT A.PN, A.原库存, C.进库, B.领料, B.领料报废, C.进料报废, [原库存]+Nz([进库],0)-Nz([领料],0)-Nz([领料报废],0)-Nz([进料报废],0) AS 库存
FROM ([SELECT TabWIPFS.PN, Sum(TabWIPFS.[Q-ok]) AS 原库存
FROM TabWIPFS
GROUP BY TabWIPFS.PN]. AS A LEFT JOIN [SELECT TabBaseFS.PN, Sum(TabBaseFS.[Q-OK]) AS 领料, Sum(TabBaseFS.[Q-SC]) AS 领料报废
FROM TabBaseFS
GROUP BY TabBaseFS.PN]. AS B ON A.PN = B.PN) LEFT JOIN [SELECT TabBaseFG.PN, Sum(TabBaseFG.[Q-OK]) AS 进库, Sum(TabBaseFG.[Q-SC]) AS 进料报废
FROM TabBaseFG
GROUP BY TabBaseFG.PN
]. AS C ON A.PN = C.PN; |
|