答案 0 :(得分:1)
根据您的数据,我进行了以下查询:
SELECT * FROM
(VALUES
(new DateTime(2019,01,01),"D1","S1","T1",20),
(new DateTime(2019,01,02),"D1","S1","T1",33),
(new DateTime(2019,01,03),"D1","S1","T1",78),
(new DateTime(2010,01,05),"D1","S2","T2",77)
) AS T(date,Dept, Subgroup, Team, Total_Employees);
@moving_Average_Last_7_Days =
SELECT DISTINCT
current.date,
current.Dept,
current.Subgroup,
current.Team,
current.Total_Employees,
AVG(lasts.Total_Employees) OVER(PARTITION BY lasts.Dept, lasts.Subgroup, lasts.Team,current.date) AS Moving_Average_Last_7_Days
FROM @moving_Average_Last_7_Days AS current
CROSS JOIN
@moving_Average_Last_7_Days AS lasts
WHERE (current.date - lasts.date).Days BETWEEN 0 AND 6
;
请告诉我您是否要实现!