Subtract value from another (new to MYSQL)

[expired user #10761]'s profile image [expired user #10761] posted 7 years ago in Running SQL scripts Permalink

Hi,

I am trying to subtract one value from another but do not get the correct outcome.

Below is how I am running the script but it adds the values together instead of subtracting:

  • SELECT ID ,(total_1 - total_2) as total FROM Payment Group by 1*

I have tried a couple of different methods I found online without any joy.

Thanks in advance for help.

ansgar's profile image ansgar posted 7 years ago Permalink

Probably total_2 already has negative values, which then turns to positive by substracting?

[expired user #10761]'s profile image [expired user #10761] posted 7 years ago Permalink

Probably total_2 already has negative values, which then turns to positive by substracting?

Hi,

Correct the total_2 have negative values.

What would be the best way to deal with this?

Thanks for quick response.

ansgar's profile image ansgar posted 7 years ago Permalink

Well I guess then total_1 + total_2 should do it, right?

Please login to leave a reply, or register at first.