此代码为我提供了重复的结果。
SELECT store_sp.Partnumber
, store_sp.ID
, dbo.installed_sp.Installed_qty
, dbo.store_sp.qty
FROM dbo.store_sp
INNER JOIN dbo.installed_sp
ON dbo.store_sp.PartID = dbo.installed_sp.part_id
and store_sp.Partnumber = installed_sp.PartNumber
我该如何解决它 https://ibb.co/n38xQk
答案 0 :(得分:-1)
你可能想要一个GROUP BY;
这将汇总您调用的行中的数量'重复'。这是我们可以从您的问题中猜出的最好的,所以请尽量提供更多信息......
SELECT store_sp.Partnumber
, store_sp.ID
, sum(dbo.installed_sp.Installed_qty) AS TotalInstalledQuantity
, sum(dbo.store_sp.qty) as TotalQuantity
FROM dbo.store_sp
INNER JOIN dbo.installed_sp
ON dbo.store_sp.PartID = dbo.installed_sp.part_id
and store_sp.Partnumber = installed_sp.PartNumber
GROUP BY
store_sp.Partnumber
, store_sp.ID