select name, (case when (sum(case when TransTypeName like 'credit%' then amount else 0 end) - sum(case when TransTypeName like 'Debit%' then amount ) else 0 end)) *5/100)<0 then 0 else (sum(case when TransTypeName like 'credit%' then amount else 0 end) - sum(case when TransTypeName like 'Debit%' then amount ) else 0 ...
You can create an int field and mark it as UNSIGNED . From MySQL 5.0 Reference Manual: INT[(M)] [UNSIGNED] [ZEROFILL] A normal-size integer. The signed range is -2147483648 to 2147483647.
We can convert Negative amount to Positive Amount using ABS() function.
In case you want to store a negative integer - (INT) will work nicely, unless it's not UNSIGNED. In case you want to store a negative decimal - (DECIMAL) is the way to go, as GBN mentioned above.
When the value of an unsigned field becomes negative it becomes a very big positive number. I use a query like this:
UPDATE table SET foo=foo+bar
I want it to become a zero when it gets negative instead of that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With