去年如何计算baclklog

时间:2019-01-29 11:51:30

标签: sql sql-server

使用与-12月的第一天的快照日期对应的BACKLOG_M的值。 例如:对于2018年1月的每个Snapdate,我们将检索Snapdate 2017年2月1日的值。

enter image description here

我尝试使用thios脚本,但未返回正确的值

select fs.*,
       (case when day(snapdate) = 1
             then max(case when day(snapdate) = 1 then backlog_y_1 end) over (partition by year_month)
        end) as backlog_y_1
from factsales  fs;

1 个答案:

答案 0 :(得分:0)

我只会使用join。很难了解表中的列,但是像这样:

select fs.*, bl.backlog_y_1
from factsales fs left join
     backlog_y_1 bl
     on year(snapdate) = year(dateadd(month, 1, bl.date)) and
        month(snapdate) = month(dateadd(month, 1, bl.date));
相关问题