php - store/select monetory values (credit/debit) mysql
I am storing monetary values in mysql database. a credit is stored as say20.00
while a debit is stored as -5.00. and then whew i need the current balance i so a
Select Sum(amount)
which in this case give me15.00
example table 1
uid amt
1 20
1 -5
example table 2
uid amt type
1 20 crd
1 5 dbt
Then in the case of a history of accounts, i can just
select * from amount
Because this is monitory values, and since database systems like mysql depreciates features every now and then i am afraid if this is the right way to do things, i also thought of adding another field which may indicate the type of transaction like
crd for credit
dbt for debit
etc
what would be your suggestions/the best way to do this?
Answer
Solution:
It would make a lot more sense to me to store the data as it is (i.e. be explicit) and use a negative number. Should you use an unsigned decimal and store the type, you can still do it though.