Oracle - select 具有特定列的最高 x 的所有行?

Oracle - select all rows with highest x of specific column?

table 中有两列:namescore

我想 select 所有具有 Score 最高 5 个值的行。

| NAME     | SCORE    |
| -------- | -------- |
| Jake     | 10       |
| Park     | 10       |
| Rone     | 9        |
| Tom      | 8        |
| Joe      | 7        |
| Clark    | 7        |
| Emily    | 6        |

请注意,它是 而非 top 5 行。我想要 所有行 具有最高 5 SCORE 值。

Oracle 中可以吗?

我用谷歌搜索并找到了 'FETCH FIRST x ROWS ONLY' 东西,但这不是我一直在寻找的东西。

你可以使用window函数:

select * from (
  select * , dense_rank() over (order by score desc) rn
  from table
) t where rn <=5