Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- match:
- id
- 1
- 2
- playermatchdata:
- id | playerid | matchid | win (boolean) | team
- 1 | 1 | 1 | 1 | 1
- 2 | 2 | 1 | 1 | 1
- 3 | 3 | 1 | 0 | 0
- 4 | 1 | 2 | 0 | 0
- 5 | 4 | 2 | 0 | 0
- 5 | 5 | 2 | 1 | 1
- 6 | 5 | 3 | 1 | 0
- 7 | 1 | 3 | 0 | 1
- player:
- id | name
- 1 | player1
- 2 | luke
- 3 | bruce
- 4 | jon
- 5 | dan
- SELECT count(playerid) as gamesplayed, player.name, count(win) as wins
- FROM match
- LEFT JOIN playermatchdata ON match.id = playermatchdata.matchid
- LEFT JOIN player ON player.id = playermatchdata.playerid
- WHERE win = 1 AND player.name = 'player1' AND team IN (
- SELECT team
- FROM playermatchdata
- LEFT JOIN player ON player.id = playermatchdata.id
- WHERE playermatchdata.matchid = pmd.matchid AND player.name = 'player1'
- )
- GROUP BY player.name
- gamesplayed | name | wins
- 1 | dan | 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement