Sales signals through SQL moving average
Question
Suppose you’re given the following tables, showing coat sales across a 10-day period:
Table: item_sales
day | item_name | num_sales |
---|---|---|
1 | Coat | 1055 |
2 | Coat | 500 |
3 | Coat | 300 |
4 | Coat | 1400 |
5 | Coat | 900 |
6 | Coat | 1000 |
7 | Coat | 1100 |
8 | Coat | 800 |
9 | Coat | 1350 |
10 | Coat | 1000 |
Using this table, write a SQL query to calculate the 3-day moving average of the number of sales, and signal when a given day is over/under that average.
Click here to view/query the tables in an interactive SQL fiddle.