As I am trying to re-learn Access after many years of not using it, I've decided to put together a database of football statistics (I'm a fantasy football addict). So far, I have been able to figure out most of the simple queries I've wanted to run, but the one I am struggling with is summing the statistics for the most recent 4 weeks (the period of time of a real-world scouting report). Here are the tables I am working with:
tbl_Offensive_Stats
+ID, Week, PlayerKey, Opp, Bye, OFPTS
tbl_Player_Info
+FirstName, LastName, PlayerPos, PlayerTeam, PlayerKey
tbl_Schedule
+ID, Team, Opp, Week, Day, Date, Time
I have also setup joins between the following tables/columns:
tbl_Offensive_Stats.PlayerKey <=> tbl_Player_Info.PlayerKey
tbl_Player_Info.PlayerTeam <=> tbl_Schedule.Team
The PlayerKey contains player information in the format: Drew Brees QB | NO
-This is how the data is exported into a csv file I am able to download from the web.
The query I am trying to run will have the following fields that will not be manipulated:
tbl_Player_Info.LastName, tbl_Player_Info.FirstName, tbl_Player_Info.PlayerPos, tbl_Player_Info.PlayerTeam
I want to be able to sum many fields (not listed) from tbl_Offensive_Stats, but to keep this post simple, I will just be using the OFPTS field. As for this field, I want to sum the OFPTS value for each player (the number of fantasy points scored each week) from only the most recent 4 weeks. I would like to have this query automatically calculate what the most recent 4 weeks are, but if I need to somehow manually enter week numbers or date ranges using BETWEEN (or something I'm not aware of), that would suffice to get this working. The tbl_Offensive_Stats table contains all the player data from each week, as I just import the weekly data into the one table. The Week field contains the week number (i.e. 1, 2, 3, etc) and not in date format.
What I have tried is variation of the following code:
And:Code:SELECT tbl_Player_Info.LastName, tbl_Player_Info.FirstName, tbl_Player_Info.PlayerPos AS Pos, tbl_Player_Info.PlayerTeam AS Team, Sum(tbl_Offensive_Stats.OFPTS) AS FPTSFROM (tbl_Player_Info INNER JOIN tbl_Offensive_Stats ON tbl_Player_Info.PlayerKey = tbl_Offensive_Stats.PlayerKey) INNER JOIN tbl_Schedule ON tbl_Player_Info.PlayerTeam = tbl_Schedule.Team GROUP BY tbl_Player_Info.LastName, tbl_Player_Info.FirstName, tbl_Player_Info.PlayerPos, tbl_Player_Info.PlayerTeam HAVING (((Sum(tbl_Offensive_Stats.OFPTS)) Between [Enter Start Date] And [Enter End Date]));
All I get with these is a blank datasheet when I run the query. After countless hours of searching and trying to find posts or blogs with similar questions that have been answered, I haven't been able to come up with anything that closely enough resembles what I am trying to do. If I need to provide any further information about what I am working with, please let me know. Any help, as always, is greatly appreciated!Code:SELECT tbl_Player_Info.LastName, tbl_Player_Info.FirstName, tbl_Player_Info.PlayerPos AS Pos, tbl_Player_Info.PlayerTeam AS Team, Sum(tbl_Offensive_Stats.OFPTS) AS FPTS FROM (tbl_Player_Info INNER JOIN tbl_Offensive_Stats ON tbl_Player_Info.PlayerKey = tbl_Offensive_Stats.PlayerKey) INNER JOIN tbl_Schedule ON tbl_Player_Info.PlayerTeam = tbl_Schedule.Team GROUP BY tbl_Player_Info.LastName, tbl_Player_Info.FirstName, tbl_Player_Info.PlayerPos, tbl_Player_Info.PlayerTeam, tbl_Schedule.Date HAVING (((Sum(tbl_Offensive_Stats.OFPTS)) Between [Enter Start Date] And [Enter End Date]));