T
Tony
I've already tried searching posts, but haven't found any similiar solutions
to this. I'm new to SQL and am using Access 2007 as my development
environment. I'm trying to keep my solution as simple as possible.
I have two relationships between two tables as follows:
GamesTable:
ID - Autonumber
Team1ID - Number (Relationship w/ TeamsTable ID)
Team2ID - Number (Relationship w/ TeamsTable ID)
Team1Score - Number
Team2Score - Number
Team1Points - Number
Team2Points - Number
TeamsTable:
ID - Autonumber
TeamName - Text
The question I'm trying to answer is to find the team that won the league.
I've been successful with finding the sum of scores for each team. The
problem lies in when I try to find out who has the most points. My code is
as follows:
SELECT Sum(Games.Team1Points) AS SumOfTeam1Points
FROM Games
GROUP BY Games.Team1ID;
Attempting to use MAX in my select statement around the SUM function is
invalid, though I'm not sure why.
Since I need to find the name of the team that won, I'm of the belief that I
need to return the correct TeamID for the team that won back to my
TeamsTable so I can then get the name. I'm under the impression I need a
subquery here, but I'm lost as to how I can return the ID of the team that
has the most points once I've summed their respective points.
Any help appreciated.
Thank you,
Tony
to this. I'm new to SQL and am using Access 2007 as my development
environment. I'm trying to keep my solution as simple as possible.
I have two relationships between two tables as follows:
GamesTable:
ID - Autonumber
Team1ID - Number (Relationship w/ TeamsTable ID)
Team2ID - Number (Relationship w/ TeamsTable ID)
Team1Score - Number
Team2Score - Number
Team1Points - Number
Team2Points - Number
TeamsTable:
ID - Autonumber
TeamName - Text
The question I'm trying to answer is to find the team that won the league.
I've been successful with finding the sum of scores for each team. The
problem lies in when I try to find out who has the most points. My code is
as follows:
SELECT Sum(Games.Team1Points) AS SumOfTeam1Points
FROM Games
GROUP BY Games.Team1ID;
Attempting to use MAX in my select statement around the SUM function is
invalid, though I'm not sure why.
Since I need to find the name of the team that won, I'm of the belief that I
need to return the correct TeamID for the team that won back to my
TeamsTable so I can then get the name. I'm under the impression I need a
subquery here, but I'm lost as to how I can return the ID of the team that
has the most points once I've summed their respective points.
Any help appreciated.
Thank you,
Tony