Table1
AutoID fMoney fRemainMoney
1 10 10
2 -5 5
3 3 8
Table2
AutoID fMoney fRemainMoney
1 10 0
2 -5 0
3 3 0
用Update 把Table2变成 Table1的样子。Update 怎么写?
update table1
set fremainmoney=(select sum(fmoney) from table1 t1 where t1.autoid<=table1.autoid)
---------------------------------------------------------------
update table1
set fremainmoney=(select sum(fmoney) from table1 t1 where t1.autoid<=table1.autoid)+(select fmoney from table1 t1 where autoid=1)
---------------------------------------------------------------
update table1
set fremainmoney=(select sum(fmoney) from table1 t1 where t1.autoid<=table1.autoid)
---------------------------------------------------------------
update table1
set fremainmoney=fmoney+isnull(select fremainmoney
from table1 t1
where t1.autoid=(select max(autoid)
from table1 t2
where t1.autoid=t2.autoid
)
)
---------------------------------------------------------------
sorry,错了,应该是:
update table1
set fremainmoney=(select sum(fmoney) from table1 t1 where t1.autoid<=table1.autoid)+(select fmoney from table1 t1 where autoid=1)
hwere autoid>1
第一条不用更新!
---------------------------------------------------------------
又错了,应该是
where autoid>1