SELECT SumGoodsArrivalVouchs.GoodsID, NZ((SumGoodsArrivalVouchs.Quantity),0) AS GoodsArrivalVouchsQuantity, NZ((SELECT SumGoodsAppVouchs.Quantity FROM (SELECT GoodsAppVouchs.GoodsID,Sum(GoodsAppVouchs.Quantity) AS Quantity FROM GoodsAppVouchs GROUP BY GoodsAppVouchs.GoodsID) AS SumGoodsAppVouchs WHERE SumGoodsAppVouchs.GoodsID=SumGoodsArrivalVouchs.GoodsID),0) AS GoodsAppVouchsQuantity, GoodsArrivalVouchsQuantity-GoodsAppVouchsQuantity AS GoodsInventoryQuantity, SumGoodsArrivalVouchs.PurchasePrice/SumGoodsArrivalVouchs.Quantity AS GoodsInventoryPrice
FROM (SELECT GoodsArrivalVouchs.GoodsID, Sum(GoodsArrivalVouchs.Quantity) AS Quantity, Sum(GoodsArrivalVouchs.Quantity*GoodsArrivalVouchs.PurchasePrice) AS PurchasePrice FROM GoodsArrivalVouchs GROUP BY GoodsArrivalVouchs.GoodsID) AS SumGoodsArrivalVouchs;