Ads were blocked - no problem. But keep in mind that developing HeidiSQL, user support and hosting takes time and money. You may want to send a donation instead.

Subtract value from another (new to MYSQL)

ramanm's profile image ramanm posted 5 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 5 years ago Permalink

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

ramanm's profile image ramanm posted 5 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 5 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.




Ads were blocked - no problem. But keep in mind that developing HeidiSQL, user support and hosting takes time and money. You may want to send a donation instead.