我已经输入以下代码来总结POLIN.Qtyremn和OELIN.Otyord中的值。它几乎可以工作,但它不是仅仅对值进行求和,而是将数量乘以4并加上它们。我认为这是由连接引起的,它调用值四次然后添加它们。
SELECT POLIN.Itemkey, POLIN.Description, POLIN.Location, INLOC.Qtyonhand, Sum(POLIN.Qtyremn), Sum(OELIN.Qtyord)
FROM X.dbo.INLOC INLOC, X.dbo.OELIN OELIN, X.dbo.POLIN POLIN
WHERE INLOC.Itemkey = POLIN.Itemkey AND INLOC.Itemkey = OELIN.Itemkey AND INLOC.Location = POLIN.Location AND INLOC.Location = OELIN.Location AND ((POLIN.Location='SPL') AND (POLIN.Qtyremn>0))
GROUP BY POLIN.Itemkey, POLIN.Description, POLIN.Location, INLOC.Qtyonhand
ORDER BY POLIN.Itemkey
答案 0 :(得分:0)
我相信这是因为你没有总结QtyOnHand - 如果我正确地理解这一点,这是一个数字...所以你不想按它分组...你想要总结它...看下面..这应该可以解决您的重复问题......
SELECT POLIN.Itemkey, POLIN.Description, POLIN.Location,
sum(INLOC.Qtyonhand) [QtyOnHand], Sum(POLIN.Qtyremn) [QtyRemn], Sum(OELIN.Qtyord) [QtyOrd]
FROM X.dbo.INLOC INLOC, X.dbo.OELIN OELIN, X.dbo.POLIN POLIN
WHERE INLOC.Itemkey = POLIN.Itemkey AND INLOC.Itemkey = OELIN.Itemkey AND INLOC.Location = POLIN.Location AND INLOC.Location = OELIN.Location AND ((POLIN.Location='SPL') AND (POLIN.Qtyremn>0))
GROUP BY POLIN.Itemkey, POLIN.Description, POLIN.Location
ORDER BY POLIN.Itemkey