gpt4 book ai didi

php - 为什么sql中total_balance的结果为零?

转载 作者:行者123 更新时间:2023-11-30 00:17:26 24 4
gpt4 key购买 nike

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中total_balance的结果为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23550264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com