如何在更新时计算单行的和


How to calculate the sum of a single row while updating them

Id  Account_name       Date         Debit   Credit
1   expense           2014-05-03     80      100
3   machinery         2014-05-03     45       0 
4   prepaid           2014-05-03     50       40
5   food              2014-05-03     50       60
6   a/p               2014-05-03     0        0 
7   rent_expense      2014-05-04     0        0
8   laundry_revenue   2014-05-04     0        0
9   accrued_revenue   2014-05-04     0        0
10  unearned_revenue  2014-05-04     0        0
11  safir             2014-05-04     0        0
12  car_rent          2014-05-04     50       80    
13  revenue           2014-05-05     40      40

在这个表中,如果我更新一行,那么我如何找到每一行的借方和贷方,如费用,机器等…

INSERT INTO transaction (account_name,dates,debit,credit)
VALUES('$account_name',curdate(),0+$debit,0+$credit)
ON duplicate KEY
UPDATE debit=VALUES(debit),credit=VALUES(credit)

如果在UPDATE子句中引用列名,它将访问该行中的旧值。

INSERT INTO transaction (account_name,dates,debit,credit)
VALUES('$account_name',curdate(),0+$debit,0+$credit)
ON duplicate KEY
UPDATE debit = debit + VALUES(debit), credit = credit + VALUES(credit)

从语句中创建var $row,然后使用下面的数学公式:

$total=$row['debit']+$row['credit'];