Reputation: 57
I have a table like this
NUMBER_ID | TOTAL |
---|---|
1 | -5000 |
1 | 5000 |
2 | 1000 |
2 | -1000 |
3 | 3000 |
4 | -3000 |
4 | 2000 |
what I want is
NUMBER_ID | TOTAL |
---|---|
3 | 3000 |
4 | -1000 |
I want do sum TOTAL from the same NUMBER_ID and when result of sum is equal to 0, then record of the NUMBER_ID and TOTAL is gone. Else of that the record still show..
Can you help me for this?
Upvotes: 0
Views: 45
Reputation: 522299
Aggregate by NUMBER_ID
and then assert that the sum of the total is not zero:
SELECT NUMBER_ID, SUM(TOTAL)
FROM yourTable
GROUP BY NUMBER_ID
HAVING SUM(TOTAL) <> 0;
Upvotes: 0