I need to show the average weight of a product over its last 4 production runs. I'm not sure how best to describe it other than an example: Let's imagine I have the following table that lists a product by date it was created, and the average weight of the product for that day:
+---------+---------+--------+
| Product | Date | Weight |
+---------+---------+--------+
| 900000 | Jan 1 | 20.0 |
| 900000 | March 3 | 12.2 |
| 900000 | July 6 | 15.0 |
| 900000 | July 7 | 14.0 |
| 900000 | Aug 6 | 3.0 |
| 800000 | June 2 | 14.0 |
| 800000 | June 3 | 12.0 |
+---------+---------+--------+
The end result I'm looking for is to add a column that includes the average Weight for the last 4 dates the product was run for, so something like this:
+---------+---------+--------+----------------+
| Product | Date | Weight | Average Weight |
+---------+---------+--------+----------------+
| 900000 | Jan 1 | 20.0 | NULL |
| 900000 | March 3 | 12.2 | NULL |
| 900000 | July 6 | 15.0 | NULL |
| 900000 | July 7 | 14.0 | NULL |
| 900000 | Aug 6 | 3.0 | 15.3 | Jan1+Mar3+July6+July7/4
| 900000 | Aug 8 | 13.0 | 11.05 | Mar3+July6+July7+Aug6/4
| 800000 | June 2 | 14.0 | NULL |
| 800000 | June 3 | 12.0 | NULL |
| 800000 | June 4 | 12.0 | NULL |
| 800000 | June 5 | 12.0 | NULL |
| 800000 | June 6 | 12.0 | 12.5 | etc...
+---------+---------+--------+----------------+
The NULL's are just there since in this sample you can't calculate the average over the last 4 runs because the data isn't there.
Could anyone point me in the direction I need to be looking to do something like this?

