Tuesday, 15 April 2014

mysql - Leaderboard : return 5 records, then the one I want, then 4 more records -


I am creating a leaderboard, and I want to be a specific user in the middle of the records.

In other words, I want a user with 5 high scores, then I want to middle, then the next 4 less:

  ** user: ** user, score Rita, 9 suo, 8 bob, 7 bills, 6 sam, 5 ** m, 4 ** & lt; - This will be the user I want in the middle. Sally, 3 Simon, 2 John, 1 Jim, 0 I can do it in PHP, but I just want to try it with a more elegant SQL statement.  

I do not really have any idea how I will explain it!

Thanks

Something to think about: < Pre> SELECT id, name from my_table; + ---- + --------- + | ID | Name | + ---- + --------- + | 1 | Adam | | 2 | Ben | | 3 | Charlie | | 4 | Adam | | 5 | Ben | | 6 | Donate + ---- + --------- from SELECT * (SELECT ID, name by name ORDER ORDER by ORDER 2) X union (SELECT ID, ID by IDECCCL2); + ---- + ------ + | ID | Name | + ---- + ------ + | 1 | Adam | | 2 | Ben | | 6 | Donate | 5 | Ben | + ---- + ------ +


No comments:

Post a Comment