SQL: Calculate 7 Day Moving Average

preview_player
Показать описание
I just realized my mistake. To get a true 7 day moving average, use RANGE instead of ROWS for your range specification.
select date, sales, avg(sales) over(order by date range between '6 days' preceding and current row)
from sales_infoorder by date;
Рекомендации по теме
Комментарии
Автор

u made it look so easy.... thank u so much

NightKingMarhoom
Автор

Nice video, thanks. Do you know if it is possible to do the same but creating a new calculated column in the database (not a query)? I am trying it but I get the following error: "You cannot use the window function 'avg' in this context".

bernietgn
Автор

Thanks a lot for the amazing video, you really made it look easy. How to remove the average data prior 7 days ? since this is 7 days of moving average data, i want the field to show the data from the 7th day and 0or Null value from day 1-6. thanks for your help!

aquilmalik
Автор

Nice video
I have a question
How to show only period/days for max/the best moving average?

adamowiczjacek
Автор

skip the first minute - waste of time google sheeting

annachan
welcome to shbcf.ru