From the course: Advanced SQL for Data Science: Time Series
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Weighted moving averages - SQL Tutorial
From the course: Advanced SQL for Data Science: Time Series
Weighted moving averages
- [Instructor] A variation on moving average is called the weighted moving average. And basically the idea is you want to give more weight to the more recent events than to the events that are farther in the past. So let's see how we could do that. We're going to start using our common table expression, WITH, and we'll use daily_avg_temp again. And I'll just type it in without detailed explanation again since we've done this a number of times. And now I'm going to create the SELECT statement with a weighted moving average. So what I'd like to do is for a particular event date I would like to know what the average temp is, and I'm just going to round it out to two decimal places. So on a particular date I'll know what the average temperature is rounded to two decimal places. And now what I'd like to do is basically weight the last, yesterday slightly heavier than the day before and slightly heavier than the day before that. So I'm going to work with three days. And I want different…
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.