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 - SQL Tutorial
From the course: Complete Guide to SQL for Data Engineering: from Beginner to Advanced
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.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Introduction to analytical functions5m 31s
-
(Locked)
Using the RANK() function7m 16s
-
(Locked)
Using the DENSE_RANK() function4m 27s
-
(Locked)
Exploring the ROW_NUMBER() function6m 35s
-
(Locked)
Understanding the LAG() and LEAD() functions7m 55s
-
(Locked)
Running totals with SUM() OVER()7m 29s
-
(Locked)
Calculating moving averages7m 33s
-
(Locked)
Challenge: Find out the sum33s
-
(Locked)
Solution: Find out the sum44s
-
(Locked)
-
-
-
-
-
-
-