Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql Query for Latest High Scores, not the Highest High scores
    primarykey
    data
    text
    <p>Edit: SOLVED by Ian &amp; Mark...</p> <p>The high scores for a game need to be fetched from a MySQL database (using php). The query I use works fine for stats that always increase in time. The query however does not work for stats that can go up or down in time.</p> <p><strong>Some details:</strong></p> <p>The stats for players are stored in the <code>stats</code> table. Multiple rows per player (all updates), an auto_increment column is Primary key.</p> <pre><code>CREATE TABLE IF NOT EXISTS `stats` ( `id` int(11) NOT NULL AUTO_INCREMENT, `stamp` bigint(20) NOT NULL, `username` varchar(255) NOT NULL, `kill` int(11) NOT NULL, `death` int(11) NOT NULL, `kdr` decimal(6,3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=956 ; </code></pre> <p>Some sample data:</p> <pre><code>1, 1365175892, user1, 1089, 191, 5.702 2, 1365175892, user2, 1805, 547, 6.709 3, 1365175892, user3, 104397, 2272, 45.949 4, 1365175892, user1, 1163, 200, 5.815 5, 1365175892, user2, 1090, 204, 5.343 </code></pre> <p>The Kills &amp; Deaths increment by time and thus it is simple to create a top 10.</p> <p><strong>The issue</strong></p> <p>For the Kill to Death Ratio (KDR), the value can go up or down in time. Example: user2 in update 5 has a lower KDR that in update 2, but still my high score list shows the highest KDR of update 2, while I actually need the lower KDR from update 5.</p> <p>So here, for the top 10, I do not need the Highest value (that would be automatically the last value stored for each player) but the LATEST value (that is not nescesarily the highest value). And I can't get it to work...</p> <p>One of the queries I tried is this one that works for increasing-only-stats:</p> <pre><code>SELECT s.* FROM stats AS s INNER JOIN ( SELECT username, MAX(kdr) AS kdr FROM stats GROUP BY username ) AS groupedstats ON s.username = groupedstats.username AND s.kdr = groupedstats.kdr ORDER BY kdr DESC LIMIT 10 </code></pre> <p>Could anyone help me how to get the the correct kdr high-score list? I'm lost...</p> <p>Thanks</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