我是一个初学者,我想:
-当总数等于0并且第二个表中的状态字段等于process时,从下表中获取recivedID
table 1 - stockTBL
table 2 - recivedTBL
这意味着当此订单中的所有产品均为0且订单状态为流程时
我想返回recivedID
这是我的代码:
SELECT s.recivedID FROM stockTBL s
JOIN recivedTBL r ON r.recivedID = s.recivedID
WHERE r.status = @STATUS
GROUP BY s.recivedID
HAVING (SUM(s.quant) = 0)
最佳答案
因此,您要选择没有库存TBL关联的所有收到的TBL记录。
SELECT s.recivedID, SUM(s.quant)
FROM stockTBL s
JOIN recivedTBL r ON r.recivedID = s.recivedID
WHERE r.status = @STATUS
GROUP BY s.recivedID
HAVING (SUM(s.quant) = 0) -- sum stockTBL