繁体   English   中英

MS Access MTD 到 YTD 值

[英]MS Access MTD to YTD values

我试图计算出每个月的 MTD 值。 这是我得到的。

在 MS 访问中,我有一个包含标题、日期和值(即 MTD)的表

Titel    Date      Value
User 1   1.1.2020  10
User 1   1.2.2020  5
User 1   1.3.2020  20
User 2   1.1.2020  5
User 2   1.2.2020  15
User 2   1.3.2020  0

我现在需要一个包含 YTD 值的新列:

Titel    Date      Value    YTD Values
User 1   1.1.2020  10       10
User 1   1.2.2020  5        15
User 1   1.3.2020  20       35
User 2   1.1.2020  5        5
User 2   1.2.2020  15       20
User 2   1.3.2020  0        20

我确实做了很多谷歌搜索,但很难在 MS Access 中找到解决方案。 是的,我需要为此使用 MS Access :)

感谢您的帮助。

EI

在 MS Access 中,您可以使用子查询:

select t.*,
       (select sum(t2.value)
        from t as t2
        where t2.titel = t.titel and
              year(t2.date) = year(t.date) and
              t2.date <= t.date
       ) as YTD
from t;

一种选择使用相关子查询:

select t.*,
    (
        select sum(t1.value) 
        from mytable as t1 
        where t1.titel = t.titel and t1.date <= t.date and year(t1.date) = year(t.date)
    ) as ytd
from mytable as t

暂无
暂无

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

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