INSERT INTO transaction (account_name,dates,debit,credit ,total_balance)
VALUES('$account_name',curdate(),$debit,$credit,total_balance=$debit+$credit)
ON DUPLICATE KEY
UPDATE debit = debit + VALUES(debit), credit = credit + VALUES(credit)
这是查询,我不知道为什么余额在总余额列中显示为零,任何机构都可以更改查询吗?
Id Account_name Date Debit Credit Total_balance
21 revenue 2014-05-05 80 55 0
23 expense 2014-05-05 48000 90000 0
28 a/p 2014-05-05 800 1000 0
最佳答案
试试这个,代替:
"INSERT INTO transaction (account_name,dates,debit,credit,total_balance)
VALUES('$account_name',curdate(),$debit,$credit,($debit+$credit))
ON DUPLICATE KEY
UPDATE debit = debit + VALUES(debit), credit = credit + VALUES(credit)"
关于php - 总余额的结果为零,为什么在sql中呢?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23550264/