MS Access MTD 到 YTD 值

MS Access MTD to YTD values

我正在尝试计算每月的 MTD 值 YTD。这是我得到的。

在 MS access 中我有一个 table 带有标题、日期和一个值(即 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