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
答案 0 :(得分: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)"