thenna thenna - 26 days ago 8x
SQL Question

Check Duplicate Records value negative and Positive In SQL server

I using SQL Server i have record Expense sheet.In this table have more than 4000o Lines Of Query . I want Short duplicate Record SQL .if Which row have same value negative and positive Record


this is my Table

Expense Id Amount:
1234 567
4141 677
3434 667
1234 - 567

but this Table I have Two Expense ID same . but value Differ Negative and Positive i want
this value LIke

Expense Id Amount:
1234 567

1234 - 567

In table I
Expense Id
I have Same Expense Id and but value is Positive and negative .but is this reverse value. i want sort Like this All table get all rows in can i get all rows ?


Does this do what you want?

select e.*
from expense e
where exists (select 1
              from expense e2
              where e2.expenseid = e.expenseid and e2.amount = - e.amount