From the course: SQL Practice: Window Functions

Unlock this course with a free trial

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

Solution: Moving average

Solution: Moving average - SQL Tutorial

From the course: SQL Practice: Window Functions

Solution: Moving average

- [Instructor] Here's how I solve this challenge. As with the previous solution, I'm using CTE notation here to save on typing. And just like in that one, we're using our three tables here to get the values we need for this challenge. We're joining orders with dishes through the orders dishes linking table. That's the same as before. So, I won't spend time here going through all that again. Let's focus on what's different in this challenge. At the beginning, we're returning the customer ID, the order ID, and the order total for each order from the orders table as the challenge requested. And here, we're taking the average of the sum of the prices of the dishes in the window we define down here. That's being rounded to two decimal places which the challenge also asked for and it's called moving average. We're partitioning the table by customer ID so we treat each group of records for the same customer ID together. And…

Contents