+# Grab all the remaining groups; we order by the simple criteria:
+# 1. If player A has gone to group X and player B hasn't, player A is higher.
+# 2. If player A has higher max score than player B, player A is higher.
+my $scores = ccbs::db_fetch_all($dbh, 'SELECT player FROM scores WHERE tournament=? AND round < ? GROUP BY round,player ORDER BY round DESC,MAX(score) DESC',
+ $tournament, $last_sround);
+for my $s (@$scores) {
+ next if ($already_ordered{$s->{'player'}});
+ $dbh->do('INSERT INTO tournamentrankings (tournament, ranking, player, points) VALUES (?,?,?,?)',
+ undef, $tournament, $ranking, $s->{'player'}, points_for_place($ranking));
+ $ranking++;
+ $already_ordered{$s->{'player'}} = 1;
+}
+