Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL How do I get highscore and number of rows as attempts

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Id  Highscore PlayerId Attempts
1   500       10    3
2   200       11    2

>Solution :

SELECT PlayerId
     , MAX(score) Highscore
     , COUNT(*) Attempts
FROM GAMES
GROUP BY PlayerId
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading