'How to take average of top 10 scores if player played 10 games

I have a table GAMES with -

g_id player1 player2 player1_score player2_score
1 1 2 320 321
2 2 3 230 300
3 1 3 341 320
4 2 4 281 311
5 4 1 256 255
6 3 1 321 333

table continues like this..

I want to create a leader board which contains average of top 10 scores of every player(if he has played 10 games)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source