简体   繁体   English

查询ms访问中的增量值

[英]incremental value in query ms access

I am making a query that shows values grouped by month, their count and their value like this: 我正在查询显示按月分组的值,它们的计数和它们的值,如下所示:

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

and I want it to contain an incremental value like this: 我希望它包含这样的增量值:

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

I can't do this at all. 我根本做不到。 I just can't or there is a way? 我不能还是有办法?

A funning value is a bit of a pain in MS Access, but you can calculate it using a correlated subquery: 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;

You can use subquery : 您可以使用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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM