查询ms访问中的增量值

时间:2018-08-10 10:29:05

标签: sql ms-access

我正在进行查询,显示按月分组的值,其计数和值,如下所示:

Month  count  value
1       7      480€
2       8      500€
3       3      250€

,我希望它包含这样的增量值:

Month  count  value  incr.  incr. val
1       7      480€   7       480€
2       8      500€   15      980€
3       3      250€   18      1230€

我根本无法做到这一点。 我只是不能还是有办法?

2 个答案:

答案 0 :(得分:1)

Funning值在MS Access中有点麻烦,但是您可以使用相关的子查询来计算它:

select t.*,
       (select sum(t2.count)
        from t as t2
        where t2.month <= t.month
       ) as running_count,
       (select sum(t2.value)
        from t as t2
        where t2.month <= t.month
       ) as running_value
from t;

答案 1 :(得分:0)

您可以使用subquery

select t.*, (select sum(t1.count)
             from table t1
             where t1.Month <= t.Month  
            ) as incr,
            (select sum(t1.value)
             from table t1
             where t1.Month <= t.Month  
            ) as incrval,
from table t;