I'm struggling with determining the MySQL code to create a column (average park_factor) in my table "starting_pitcher_stats" that I'd like to contain the season-to-date in-season average values of the values in another column (park_factor). I'd like this in-season average to be grouped by pitcher and by date.
Ideally, the table would look like this:
pitcher park_fac avg_park_fac date
aased001 94 94 1977-07-31
aased001 100 97 1977-08-06
aased001 108 100.666 1977-08-11
aased001 108 102.5 1977-08-16
aased001 96 101.2 1977-08-21
aased001 108 102.33 1977-08-26
aased001 108 103.14 1977-08-31
aased001 104 103.25 1977-09-05
aased001 108 103.77 1977-09-10
aased001 92 102.6 1977-09-16
aased001 106 102.9 1977-09-22
aased001 108 103.33 1977-09-27
The code I'm using is:
SELECT Starting_Pitcher, full_park_factor, AVG(full_park_factor), Game_Date
FROM starting_pitcher_stats
GROUP BY Starting_Pitcher, Game_Date, Game_Number
...and a sample of the resulting table looks like this:
pitcher park_fac avg_park_fac date
aased001 94 94.0000 1977-07-31
aased001 100 100.0000 1977-08-06
aased001 108 108.0000 1977-08-11
aased001 108 108.0000 1977-08-16
aased001 96 96.0000 1977-08-21
aased001 108 108.0000 1977-08-26
aased001 108 108.0000 1977-08-31
aased001 104 104.0000 1977-09-05
aased001 108 108.0000 1977-09-10
aased001 92 92.0000 1977-09-16
aased001 106 106.0000 1977-09-22
aased001 108 108.0000 1977-09-27
Can someone help please?
Thank you in advance for help with this. Lee