首页 > 解决方案 > MYSQL 按日期累计总和

问题描述

我怎样才能做累积和?

我的查询是:

select dateb,ricetype,bajet1
from bajet
where ricetype='grand total'

我如何归档“新价值”?

预期成绩

标签: mysql

解决方案


你可以这样做:

set @CumSum := 0;
select dateb, ricetype, bajet1, (@CumSum := @CumSum + bajet1) as New_Value
from bajet where ricetype='grand total';

推荐阅读