M
MikeB
I'm writing queries galore. Perhaps there is something I don't "get."
In my chess database, if I want to know how a player has performed, I
wrote several queries.
One to calculate the number of games they won:
SELECT PlayerGames.PlayerNumber, Count(PlayerGames.Score) AS Won
FROM Tournaments INNER JOIN (PlayerGames INNER JOIN Matches ON
PlayerGames.MatchNumber = Matches.MatchNumber) ON
Tournaments.TournamentNumber = Matches.TournamentNumber
WHERE (((PlayerGames.Score)=1) AND ((PlayerGames.Color)="White" Or
(PlayerGames.Color)="Black"))
GROUP BY PlayerGames.PlayerNumber, Tournaments.TournamentNumber
HAVING (((Tournaments.TournamentNumber)=[Tournament?]));
Another to calculate the number of games played as White:
SELECT PlayerGames.PlayerNumber, Count(PlayerGames.PlayerNumber) AS
White
FROM Tournaments INNER JOIN (PlayerGames INNER JOIN Matches ON
PlayerGames.MatchNumber = Matches.MatchNumber) ON
Tournaments.TournamentNumber = Matches.TournamentNumber
WHERE (((Tournaments.TournamentNumber)=[Tournament?]) AND
((PlayerGames.Color)="White"))
GROUP BY PlayerGames.PlayerNumber;
Another for games lost, games drawn, games as black... you get the
picture.
Then I write a query to combine all of those into one table:
SELECT Players.PlayerNumber, Players.Firstname & " " &
Players.LastName AS Name, [GamesPlayed - White].White, [GamesPlayed -
Black].Black, [GamesPlayed - Bye].Byes AS Byes, [GamesPlayed -
Won].Won, [GamesPlayed - Lost].Lost, [GamesPlayed - Drawn].Draws AS
Draws, [GamesPlayed - Instruction].Instruction, [GamesPlayed -
Beginner].Beginner
FROM (((((((Players LEFT JOIN [GamesPlayed - White] ON
Players.PlayerNumber = [GamesPlayed - White].PlayerNumber) LEFT JOIN
[GamesPlayed - Black] ON Players.PlayerNumber = [GamesPlayed -
Black].PlayerNumber) LEFT JOIN [GamesPlayed - Bye] ON
Players.PlayerNumber = [GamesPlayed - Bye].PlayerNumber) LEFT JOIN
[GamesPlayed - Instruction] ON Players.PlayerNumber = [GamesPlayed -
Instruction].PlayerNumber) LEFT JOIN [GamesPlayed - Beginner] ON
Players.PlayerNumber = [GamesPlayed - Beginner].PlayerNumber) LEFT
JOIN [GamesPlayed - Drawn] ON Players.PlayerNumber = [GamesPlayed -
Drawn].PlayerNumber) LEFT JOIN [GamesPlayed - Lost] ON
Players.PlayerNumber = [GamesPlayed - Lost].PlayerNumber) LEFT JOIN
[GamesPlayed - Won] ON Players.PlayerNumber = [GamesPlayed -
Won].PlayerNumber;
Each and evey one of the above queries asks as a parameter for the
Tournament that the player played in.
Now I need to get lifetime performance of the player. I can't find a
way to make the parameter accept "All" or "*" tournaments, so it seems
I have to write each of the above queries again, and create another
summary query.
Now while it is not difficult to simply copy each of the queries,
modify it and save it, I'm just starting to have queries coming out of
the wazoo (pardon my expression). Is there a trick of the trade that
I'm missing or overlooking that will simplify my life?
Aside: Just looking at these queries, I noticed that some of them
still use the "HAVING" clause as opposed to the "WHERE" clause. I'll
get right on to that to fix that.
In my chess database, if I want to know how a player has performed, I
wrote several queries.
One to calculate the number of games they won:
SELECT PlayerGames.PlayerNumber, Count(PlayerGames.Score) AS Won
FROM Tournaments INNER JOIN (PlayerGames INNER JOIN Matches ON
PlayerGames.MatchNumber = Matches.MatchNumber) ON
Tournaments.TournamentNumber = Matches.TournamentNumber
WHERE (((PlayerGames.Score)=1) AND ((PlayerGames.Color)="White" Or
(PlayerGames.Color)="Black"))
GROUP BY PlayerGames.PlayerNumber, Tournaments.TournamentNumber
HAVING (((Tournaments.TournamentNumber)=[Tournament?]));
Another to calculate the number of games played as White:
SELECT PlayerGames.PlayerNumber, Count(PlayerGames.PlayerNumber) AS
White
FROM Tournaments INNER JOIN (PlayerGames INNER JOIN Matches ON
PlayerGames.MatchNumber = Matches.MatchNumber) ON
Tournaments.TournamentNumber = Matches.TournamentNumber
WHERE (((Tournaments.TournamentNumber)=[Tournament?]) AND
((PlayerGames.Color)="White"))
GROUP BY PlayerGames.PlayerNumber;
Another for games lost, games drawn, games as black... you get the
picture.
Then I write a query to combine all of those into one table:
SELECT Players.PlayerNumber, Players.Firstname & " " &
Players.LastName AS Name, [GamesPlayed - White].White, [GamesPlayed -
Black].Black, [GamesPlayed - Bye].Byes AS Byes, [GamesPlayed -
Won].Won, [GamesPlayed - Lost].Lost, [GamesPlayed - Drawn].Draws AS
Draws, [GamesPlayed - Instruction].Instruction, [GamesPlayed -
Beginner].Beginner
FROM (((((((Players LEFT JOIN [GamesPlayed - White] ON
Players.PlayerNumber = [GamesPlayed - White].PlayerNumber) LEFT JOIN
[GamesPlayed - Black] ON Players.PlayerNumber = [GamesPlayed -
Black].PlayerNumber) LEFT JOIN [GamesPlayed - Bye] ON
Players.PlayerNumber = [GamesPlayed - Bye].PlayerNumber) LEFT JOIN
[GamesPlayed - Instruction] ON Players.PlayerNumber = [GamesPlayed -
Instruction].PlayerNumber) LEFT JOIN [GamesPlayed - Beginner] ON
Players.PlayerNumber = [GamesPlayed - Beginner].PlayerNumber) LEFT
JOIN [GamesPlayed - Drawn] ON Players.PlayerNumber = [GamesPlayed -
Drawn].PlayerNumber) LEFT JOIN [GamesPlayed - Lost] ON
Players.PlayerNumber = [GamesPlayed - Lost].PlayerNumber) LEFT JOIN
[GamesPlayed - Won] ON Players.PlayerNumber = [GamesPlayed -
Won].PlayerNumber;
Each and evey one of the above queries asks as a parameter for the
Tournament that the player played in.
Now I need to get lifetime performance of the player. I can't find a
way to make the parameter accept "All" or "*" tournaments, so it seems
I have to write each of the above queries again, and create another
summary query.
Now while it is not difficult to simply copy each of the queries,
modify it and save it, I'm just starting to have queries coming out of
the wazoo (pardon my expression). Is there a trick of the trade that
I'm missing or overlooking that will simplify my life?
Aside: Just looking at these queries, I noticed that some of them
still use the "HAVING" clause as opposed to the "WHERE" clause. I'll
get right on to that to fix that.