我在表收据中有这样的数据,因为正值是货物的收货金额,而在退货时是负值。
在上图中,Receiver_No 01267A是收到Qty_Received 1的第一个项目。然后在收货号码01268A上有货物退货。我希望这笔交易不会出现。
这是我试过的声明。
select I2.Receiver_No,
I2.Purchase_order,
I2.PO_Line,
I2.Qty_received
from (Select Purchase_order,
PO_Line
from Receipts
group by Purchase_order,
PO_Line
having sum(qty_received) <>'0') I1 inner join
Receipts I2 On
I1.Purchase_Order = I2.Purchase_Order and
I1.PO_Line = I2.PO_Line
但结果并不符合我的要求。 请帮助。
答案 0 :(得分:0)
这适用于您提供的非常有限的数据。如果您想提供有关数据外观的更多信息,那么更容易找到更好的解决方案。
如果您的数据包含大量具有相同数量的行,则此解决方案将无效。
SELECT
r.Receiver_No, r.Purchase_order, r.PO_Line, r.Qty_received
FROM
receipts r
WHERE
NOT EXISTS (SELECT
purchase_order
FROM
receipts s
WHERE
r.qty_received = -s.qty_received
)
答案 1 :(得分:-1)
如果您的要求是获取数量小于1的行而不是负数:
SELECT * FROM Receipts WHERE ABS(QtyRecvd) >0 AND ABS(QtyRecvd) < 1
答案 2 :(得分:-1)
试试这个
SELECT * FROM Receipts where Qty_received>0 AND Qty_received < 1