Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update positive to negative value in mysql

Tags:

mysql

i have payment table fields

enter image description here

update reason and amount & total field are change negative

UPDATE payment 
SET reason = 'refund' 
WHERE uid =5 AND date = '2012-05-01' AND accid =2 

update single query is it possible?

like image 762
Vaishu Avatar asked Jun 27 '12 12:06

Vaishu


2 Answers

Use ABS(amount) if you wish to always get the positive integer.

SELECT ABS(5);

will output 5

SELECT ABS(-5);  

will also output 5

like image 197
Andrew Atkinson Avatar answered Sep 27 '22 16:09

Andrew Atkinson


If I understand you correctly, you also want to set amount column to positive value along with the above statement.

You can use something like this

UPDATE payment 
SET reason = 'refund', amount = amount * -1, total = total * -1
WHERE uid =5 AND date = '2012-05-01' AND accid =2
like image 36
Fahim Parkar Avatar answered Sep 27 '22 18:09

Fahim Parkar