SQL Query | How to calculate rolling / moving average ? | Ex - 3 day rolling average

  Рет қаралды 10,038

Learn at Knowstar

Learn at Knowstar

Күн бұрын

Пікірлер: 25
@jomeks5031
@jomeks5031 2 жыл бұрын
Hi. What if i want to set to null the moving average with not enough rows... Like in your example the first two rows?
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
This is a great question. Thank you for mentioning this scenario. You can use RowNumber function to calculate the Row Numbers and start the calculation only from the 3rd row. You can use CASE or IFF to perform this check - Please see example below - IIF(ROW_NUMBER() OVER(PARTITION BY FA.CurrencyKey ORDER BY DateKey)>=3,AVG(EndofDayRate) OVER (PARTITION BY FA.CurrencyKey ORDER BY DateKey ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) , NULL) AS _3DAYROLLINGAVG
@terryh558
@terryh558 2 жыл бұрын
Good job on your videos. I keep looking for more! As to the Moving Average of a Stock or Currency a) it should not start computing anything until you have number of days = moving average length, b) you do NOT want to fill in missing dates because (barring data errors) those are days when the market is closed like Sat/Sun/Holidays. Those days are just ignored. We could row_number the data, oldest data first, and use that to put NULL into the first 13 days if your MA length = 14. I seem to recall seeing a graphing feature in SSMS. If so, I'd like to see how to put this same data into a graph.
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Thank you for sharing this. These insights really help all of us learn and grow. 👍
@payalia08
@payalia08 Жыл бұрын
Just got this task for my job thanks in advance😄
@LearnatKnowstar
@LearnatKnowstar Жыл бұрын
Hope it helped
@vpnath75
@vpnath75 2 жыл бұрын
Very informative! I would also be interested in seeing an explanation for the exponential moving average. Thanks!
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Thank you. We will posting the video in exponential rolling average soon 👍
@aduvalasatheeshkumar4840
@aduvalasatheeshkumar4840 2 жыл бұрын
Great Explanation...! Can you tell me a logic to get the previous row value if the curent row field is empty. Thanks ...!
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Thank you. You can get previous rows with lag function. If the row is entirely missing, you would first need to create a dummy record for the missing row.
@samuelfsdev
@samuelfsdev 2 жыл бұрын
It's a greate content! These videos reawaken my interest in database management.
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Glad these are useful. Thanks 🙏
@diydecor2653
@diydecor2653 2 жыл бұрын
Simple and easy to understand
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Thank you 🙏
@VinayKumar-lb3lq
@VinayKumar-lb3lq 2 жыл бұрын
Hi, can u pls make videos on recursive querys from start to end.
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Yes sure. We are planning a series on SQL/DB concepts soon and these topics will be covered there. 👍
@varshadeore154
@varshadeore154 11 ай бұрын
thanks.. very helpful
@LearnatKnowstar
@LearnatKnowstar 11 ай бұрын
Thank you
@amukelaniebenezer406
@amukelaniebenezer406 Жыл бұрын
Thank you.
@kristyowens2284
@kristyowens2284 2 жыл бұрын
Once again great explanation. Thanks!
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Thank you 🙏
@mainlykanchan8740
@mainlykanchan8740 2 жыл бұрын
Ma'am will you please solve leetcode queries?
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Sure. We are planning soon 👍
@nikolaybaranov2213
@nikolaybaranov2213 2 жыл бұрын
Thanks, very helpful!
@LearnatKnowstar
@LearnatKnowstar 2 жыл бұрын
Thank you 🙏
SQL Query | How to calculate YTD and MTD totals | Window Functions
16:01
Learn at Knowstar
Рет қаралды 42 М.
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 287 МЛН
这是自救的好办法 #路飞#海贼王
00:43
路飞与唐舞桐
Рет қаралды 112 МЛН
SQL Tricks | How to find value in multiple columns ?
13:09
Learn at Knowstar
Рет қаралды 12 М.
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 287 МЛН