Note that there are some explanatory texts on larger screens.

plurals
  1. POEfficient way to SELECT a fixed range of high scores given only a user id
    primarykey
    data
    text
    <p>I have a table consisting of records of every match that every player has played. I've gotten a pretty good head start from the top answer of this question: <a href="https://stackoverflow.com/questions/5436263/ranking-with-millions-of-entries">Ranking with millions of entries</a>, and am currently using this query to retrieve each player's highest score and their rank:</p> <pre><code>SET @rank=0; SELECT user_id, score, rank FROM ( SELECT *, @rank := @rank + 1 as rank FROM high_scores JOIN ( SELECT user_id as user_id2, MAX(score) AS max_score FROM high_scores GROUP BY user_id2 ORDER BY max_score DESC) AS max_score_table ON max_score = high_scores.score AND high_scores.user_id = user_id2) derived_table ORDER BY rank; </code></pre> <p>Again, this gives me a nice ordered list of each player's top score and its rank; However, I'd also like to be able to supply a specific <code>user_id</code> and filter the results down to this user's score as well as X amount of surrounding higher and lower scores. </p> <p>I would think I'd need to perform a <code>SELECT ... WHERE</code> on "derived_table" for the <code>user id</code> and use the returned row's <code>'rank'</code> to filter the top-level <code>SELECT</code> statement, but in addition to the query not even being accepted ('derived_table doesn't exist'), the way I was doing it would have required me to re-query derived_table twice (for a greater-than and less-than test), making the query even less efficient than it probably should be.</p> <p>How can I filter the full list of high scores and ranks down to a single <code>user_id</code>'s entry and X amount of surrounding entries? Any insight on the code I'm trying to come up with (or the code I currently have) would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload