这真的不是那么复杂,但我无法绕过它。我已经彻底搜索过,但即便想出这个问题的搜索字符串或标题也很难。解释将告诉所有人:
答案 0 :(得分:0)
首先创建一个查询,该查询为您提供 imageLiveCount 表中每个 PO 的计数:
SELECT i.PO, Count(*) AS CountOfInstances
FROM imageLiveCount AS i
GROUP BY i.PO
如果该查询返回您想要的内容,请将其加入 labelDrops 表并计算 QtyLeft :
SELECT
l.PO,
l.Qty,
(l.Qty - sub.CountOfInstances) AS QtyLeft
FROM
labelDrops AS l
INNER JOIN
(
SELECT i.PO, Count(*) AS CountOfInstances
FROM imageLiveCount AS i
GROUP BY i.PO
) AS sub
ON l.PO = sub.PO