我是初学者,我想: - 当total quant equal = 0且第二个表中的status字段等于process时,从下表中获取recivedID table 1 - stockTBL
表示此订单中的所有产品均为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)
答案 0 :(得分:1)
因此,您希望选择所有没有stockTBL关联的receivedTBL记录。
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
答案 1 :(得分:0)
我假设您需要SQL代码来实现这一目标:
SELECT T1.recivedID
FROM TABLE1 T1
INNER JOIN TABLE2 T2 ON T1.recivedID = t2.recivedID
WHERE T1.quant = 0
AND T2.status = @status