首页 > 解决方案 > 查询毫秒访问中的增量值

问题描述

我正在做一个查询,显示按月份分组的值、它们的计数和它们的值,如下所示:

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€

我根本做不到。我就是不能还是有办法?

标签: sqlms-access

解决方案


有趣的值在 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;

推荐阅读