如果您忽略同一玩家可能因技能不同而多次被选中,则查询可能如下所示:
select player_id, player_name
from (
select player_id, player_name,
rank() over(order by attack_skill desc) attack_rank,
rank() over(order by defense_skill desc) defense_rank,
rank() over(order by passing_skill desc) passing_rank,
rank() over(order by gk_skill desc) gk_rank
from profile_players
)
where attack_rank <= 3 or defense_rank <= 4
or passing_rank <= 3 or gk_rank <= 1;
为确保您获得正好 11 名玩家,您必须应用一些技巧:
select player_id, player_name
from (
select player_id, player_name,
least((attack_rank - 1) / 3, (defense_rank - 1) / 4,
(passing_rank - 1) / 3, gk_rank - 1) blended_rank
from (
select player_id, player_name,
rank() over(order by attack_skill desc) attack_rank,
rank() over(order by defense_skill desc) defense_rank,
rank() over(order by passing_skill desc) passing_rank,
rank() over(order by gk_skill desc) gk_rank
from profile_players
)
order by blended_rank desc
)
where rownum <= 11;
然后,如果您确实需要一个过程,则可以将此查询包装到一个存储过程中。