Happy Thanksgiving!!
This post is for learning and educational purpose only
Structure of table, insert statements and SQL query are updated in below db fiddle link to keep this post clean and short. Please refer below link:
I am trying to calculate "7 Days moving average" and also to add computed columns based on this new column "7 days moving average". Tried different methods and was getting error "window functions are not allowed here". Later tried in excel spreadsheet and got the formula working. Still not sure how to achieve this in SQL with Match_Recognize and hence seeking help from you all experts.
Please note: I am uploading screenshots of excel and formulae since stackoverflow not giving me option to upload the excel spreadsheet.
Below is the output I am expecting (Column highlighted in yellow):
Update: Thank you for suggestion and for correcting me. Updated the post.
Tricky Part:
Column "7_MOV_AVG": Row 8 (As per excel serial number) is average of cells E2 to E8
Whereas Row 9 (As per excel serial number) onwards the formula considers previous row values and not sure how to achieve that. Below is the screenshot for the calculation:
Appreciate any help with this. Thanks in advance.
Thanks,
Richa