Created
November 24, 2022 15:12
-
-
Save mshakhomirov/ebf5488d0036bc9b84ae05889346d986 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with dates as ( | |
select | |
dt | |
from | |
unnest(generate_date_array(date_sub(current_date(), interval 90 day), current_date(), interval 1 day)) as dt | |
) | |
, data as ( | |
select dt | |
, CEIL(RAND()*1000) as revenue -- just some random data. | |
from | |
dates | |
) | |
select | |
dt | |
, revenue | |
, AVG(revenue) OVER(ORDER BY unix_date(dt) RANGE BETWEEN 6 PRECEDING AND CURRENT ROW) as seven_day_moving_average | |
from data | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment