如果性能是一个问题,则可以使用MySQL变量:
set @csum := 0;update YourTableset cumulative_sum = (@csum := @csum + count)order by id;
或者,您可以删除该
cumulative_sum列并在每个查询中对其进行计算:
set @csum := 0;select id, count, (@csum := @csum + count) as cumulative_sumfrom YourTableorder by id;
这以运行方式计算运行总和:)



