FOR tp IN SELECT * FROM temp_minmax LOOP
ret.player = tp.player;
ret.best_rank = 1 + ( SELECT COUNT(*) FROM temp_minmax WHERE min_score >= tp.max_score AND player<>tp.player);
FOR tp IN SELECT * FROM temp_minmax LOOP
ret.player = tp.player;
ret.best_rank = 1 + ( SELECT COUNT(*) FROM temp_minmax WHERE min_score >= tp.max_score AND player<>tp.player);