I have one table that I need two counts from. The table holds information about a sports game. I want the number of games won and the number of games tied for a given team.
Table: Game
Fields: Game_ID,Home_Team_ID,Away_Team_ID,Win_Team_ID
If the game was a tie then Win_Team_ID = -1 instead of the approriate Team_ID.
Can someone please tell me what is wrong with my SQL;
Select Count(g2.Game_ID) As Tie_Count, Count(g1.Game_ID)
As Win_Count
From Game g2, Game g1
where (g1.Win_Team_ID = 8) or
((g2.Win_Team_ID =-1) and
(g2.Home_Team_ID = 8 or g2.Away_Team_ID = 8))
In this example I hard coded the Team_ID value, if I separate the query they each work fine, but when together I get too many rows returned and I get the same value for each count.
Table: Game
Fields: Game_ID,Home_Team_ID,Away_Team_ID,Win_Team_ID
If the game was a tie then Win_Team_ID = -1 instead of the approriate Team_ID.
Can someone please tell me what is wrong with my SQL;
Select Count(g2.Game_ID) As Tie_Count, Count(g1.Game_ID)
As Win_Count
From Game g2, Game g1
where (g1.Win_Team_ID = 8) or
((g2.Win_Team_ID =-1) and
(g2.Home_Team_ID = 8 or g2.Away_Team_ID = 8))
In this example I hard coded the Team_ID value, if I separate the query they each work fine, but when together I get too many rows returned and I get the same value for each count.