这个我建议你从数据集上去考虑解决问题。
如果是oracle数据库的话,查询用的sql语句如下:
select t1.thisValue + decode( t1.laterValue ,null,0,t1.laterValue) as value
from
(
select t.balance as thisValue, lag(t.balance) over(order by id) as laterValue from table_name t
) t1
,
然后取value就OK了。
如果是sql server的话,sql写法大致如下:
SELECT t.balance,
(select sum(balance) from table_name t2 where t2.id<=t.id) as laterValue
FROM table_name t
order by id
有问题请MQQ8541413。
希望能帮到你。