Didn't want to do this (ask for help) but I'm stumped...
I'm writing a hockey pool program and one of the functions is to calculate a total amount of weekly points for all players (Goalies and Skaters) "playing" for a particular Pool Team.
I've got 3 tables.
**PoolTeams**
PoolTeamID PoolTeamName
---------- ------------
1 Team A
2 Team B
3 Team C
**MondaySkaterStats**
Player Weeknumber PoolTeam PTS Status
------ ---------- -------- --- ------
10 1 1 15 True
11 2 1 3 False
13 3 2 5 True
40 1 1 3 True
41 2 1 5 False
43 3 2 1 True
**MondayGoalieStats**
Player Weeknumber PoolTeam PTS Status
------ ---------- -------- --- ------
20 1 3 4 False
21 2 1 3 True
22 3 2 5 False
50 1 3 4 False
51 2 1 3 True
52 1 1 7 True
The actual database is much bigger, I have truncated is considerably for clarity.
Also, MondayGoalieStats table has a few extra columns which are not relevant to the outcome of the results.
So let's say I want to sum up points of all players playing for each Pool Team (Skaters and Goalies) that have a Status of TRUE and I'm interested in Week #1 only.
Here is an SQL Query I came up with. It works great when summing up MondaySkaterStats points but for whatever reason it doesn't seem to properly sum up points in the MondayGalieStats table. I decided to go with INNER JOIN since the Player and Goalie tables are not exactly the same. I used Weeknumber as the common point between the two.
SELECT PT.PoolTeamName, SUM(MS.PTS) AS PlayerSum, SUM(MG.PTS) as GoalieSum
FROM PoolTeams PT, MondaySkaterStats MS
INNER JOIN MondayGoalieStats MG ON (MS.Weeknumber=MG.Weeknumber)
WHERE MS.Weeknumber=1
AND PT.PoolTeamID = MS.PoolTeam
AND MS.PoolTeam = MG.PoolTeam
AND MS.Status = True
AND MG.Status = True
GROUP BY PT.PoolTeamName
Any help would be greatly appreciated.... thanks!