I have 2 tables PLAYERS and GAMES When a new game starts, I add a new GAME record with a playerID to the database, so the data might look like this:
GAMES
Id Score PlayerId
1 200 10
2 100 10
3 500 10
4 100 11
5 200 11
Question: How do I query this if I want to get the highest score and sum of rows as the number of attempts, to get this result:
Id Highscore PlayerId Attempts
1 500 10 3
2 200 11 2
CodePudding user response:
SELECT PlayerId
, MAX(score) Highscore
, COUNT(*) Attempts
FROM GAMES
GROUP BY PlayerId