distal-attribute
distal-attribute
distal-attribute
distal-attribute

Subtract value from another (new to MYSQL)

ramanm posted 3 weeks ago in Running SQL scripts

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 posted 3 weeks ago

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

ramanm posted 3 weeks ago

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 posted 3 weeks ago

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

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