From the course: Complete Guide to SQL for Data Engineering: from Beginner to Advanced

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Calculating moving averages

Calculating moving averages

- [Instructor] Moving Averages. Assume that you want to understand the trend in daily temperatures in your city. To figure out whether it is getting warmer or cooler over time, you collect the temperature data every day for a month. Now, instead of looking at the raw daily temperature, you decide to calculate a seven-day moving average. This means, for each day, you take the average of temperature on that day and the temperature of the six preceding days. This smoothens out the daily fluctuation, and you can get the trend line. Here how it works. On day one, let's say your temperature is 75 degree Fahrenheit. Now the seven-day moving average for day one will become 75. On day two, the temperature was 78, so your seven-day average will become 76.5. On day three, imagine the temperature is 80 degree Fahrenheit. Now the seven-day moving average will now become equals to 77.67. And similarly, it will go on for 30 days.…

Contents