Update positive value to negative value in mysql

I have payment table fields

enter image description here

Update the reason, and the amount and total field are negative

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

Can I update one request?

+8
source share
3 answers

If you understand correctly, you also want to set a column with a 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
+16
source

Use ABS(amount)if you want to always get a positive integer.

SELECT ABS(5);

prints 5

SELECT ABS(-5);  

also displays 5

+4
source

, :

SELECT @TotalAmount:=( SELECT FORMAT(SUM(Amount),   4)  FROM MPPayment WHERE PaymentBatchID = 6 and CompanyID=3);

:

enter image description here

:

SELECT @TotalAmount:=( SELECT FORMAT(SUM(Amount),   4)  FROM MPPayment WHERE PaymentBatchID = 6 and CompanyID=3);
SELECT @TotalAmount * -1;

enter image description here , .

, :

SELECT @TotalAmount:=( SELECT SUM(Amount)  FROM MPPayment WHERE PaymentBatchID = 6 and CompanyID=3);
 select FORMAT((0 - @TotalAmount), 4 ); 

, , . :

enter image description here

-1:

 SELECT @TotalAmount:=( SELECT SUM(Amount)  FROM MPPayment WHERE PaymentBatchID = 6 and CompanyID=3);
 select FORMAT(( @TotalAmount *-1), 4 );
0
source

All Articles