在sql中,为什么总余额的结果为零?

时间:2014-05-08 18:55:25

标签: php mysql

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

1 个答案:

答案 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)"