QueryStash
Window functions make it very easy to calculate a moving average across a time series dataset.
We can use the ORDER BY date field and ROWS BETWEEN to define our moving average window.
1AVG(value) OVER( 2 ORDER BY date_field 3 ROWS BETWEEN 6 PRECEDING AND CURRENT ROW 4) AS moving_average
Created: Sep 1st 2020
Made with ❤️ by @Yekalb
© 2024 Query Stash. All rights reserved
Resources
Examples
Stay up to date