+ # Get the total list of scores for each player in this round, and pick
+ # out the best N
+ $people = [];
+ my $q = $dbh->prepare('SELECT parallel,player,SUM(score) AS score FROM scores WHERE tournament=? AND round=? GROUP BY parallel,player ORDER BY parallel, SUM(score) DESC');
+ $q->execute($tournament, $round - 1);
+
+ my ($parallel,$num_from_this_parallel);
+
+ while (my $ref = $q->fetchrow_hashref()) {
+ if (!defined($parallel) || $parallel != $ref->{'parallel'}) {
+ $parallel = $ref->{'parallel'};
+ $num_from_this_parallel = 0;
+ }
+ if ($num_from_this_parallel++ < $num_qual_prev) {
+ push @$people, {%$ref};
+ }
+ }
+}
+
+if ($num_groups == 1) {
+ # Everybody's in the same group
+ my $position = 1;
+ for my $p (@$people) {
+ $dbh->do('INSERT INTO roundparticipation (tournament, round, parallel, player, position) VALUES (?, ?, ?, ?, ?)', undef,
+ $tournament, $round, 0, $p->{'player'}, $position);