如何找到一个具有负值而另一个具有相同正值的记录

时间:2013-02-26 15:37:34

标签: sql tsql

如何找到一个具有负值而另一个具有相同正值的记录。 我已经尝试过这样的事情,但它们没有用。

 where [Check_Number]=[Check_Number] and Payment_Amount = ([payment_amount]/-1)

1 个答案:

答案 0 :(得分:0)

这个怎么样:

where a.check_Number + b.check_number = 0 and a.check_number < 0

或者,两个字段是payment_amount和check_number吗?

where payment_amount = - check_number and check_number < 0

也许是这样的?

select r1.check_number, r1.payment_amount, r2.check_number, r2.payment_amount
from records r1 join
     records r2
     on r1.check_number = r2.check_number and
        r1.payment_amount = - r2.payment_amount