I am programming an application to keep score for darts. I’ve created a relational database as the following:
GameInformation
gameId | numberOfPlayer | totalInnings | gameType
0 | 2 | 13 | 0
1 | 2 | 14 | 0
2 | 2 | 20 | 0
3 | 3 | 16 | 0
PlayersByGame
gameId | playerId | innings | mpr
0 | 0 | 13 | 1.538
0 | 1 | 13 | 1.651
1 | 0 | 14 | 1.500
1 | 1 | 14 | 2.012
2 | 0 | 20 | 1.658
2 | 2 | 20 | 2.123
3 | 2 | 16 | 2.001
3 | 1 | 16 | 1.325
3 | 0 | 16 | 1.001
Players
Name | Id
Dainon | 0
Andy | 1
Keith | 2
I’m familiar with simple SQL queries but and not sure how to get the number of games played by a player (Dainon) who played against a player (Andy) without the games that have more than 2 players and where only Dainon and Andy played against each other. At the time of the query, I have both Dainon and Andy’s player IDs.
Could anyone provide any insight as to how I write a SELECT statement to do that.
I’ve started with wrong queries such as the following:
SELECT * FROM PlayersByGame WHERE playerId LIKE 0 and playerId LIKE 1;
SELECT gameId, numberOfPlayers, totalInnings, gameType
FROM GameInformation
WHERE (numberOfPlayers = 2)
UNION
SELECT gameId, playerId, innings, mpr
FROM PlayersByGame
WHERE (playerId = 0)
UNION
SELECT gameId, playerId, innings, mpr
FROM PlayersByGame AS PlayersByGame_1
WHERE (playerId = 1)
Thank you, I appreciate any of your assistance!
Try this.
Click her for Sqlfiddle version of it