我可以使用下面的代码获得每周的总条目。
select week(date_created) as week, count(distinct tag_code) as Total_This_Week
from entries
where date_created between '2000-01-01' and '2020-01-01'
group by week;
但我需要得到的是total_last_6_weeks
下面这样的列,它是前 6 周的加起来,所以第 6 周的total_Last_6_weeks
“370”是通过加起来得到的(56+45+85+34+85+65)。这必须每周发生,所以第 9 周必须将前 6 周相加。我尝试过的一切似乎都不起作用。
+-----+-----------------+--------------------+
| week| Total_This_Week | total_Last_6_Weeks |
+-----+-----------------+--------------------+
|__0__|_______81________|_______ 122________ |
|__1__|_______65________|________188________ |
|__2__|_______85________|________145_________|
|__3__|_______34________|________205_________|
|__4__|_______85________|________189_________|
|__5__|_______45________|________112_________|
|__6__|_______56________|________370_________|
|__7__|_______32________|________518_________|
|__8__|_______34________|________121_________|
|__9__|_______45________|________224_________|
+-----+-----------------+--------------------+