我想知道是否有 单 Oracle函数,该函数将使我在关系中的排名最低(下图的THIS列),而不是最高排名。我知道我可以获取RANK的输出并得出我想要的东西。我只是想知道我是否忽略了另一个函数或函数选项。谢谢。
答案 0 :(得分:4)
您可以使用range between
限定词:
with t as (
select 10 as score from dual union all
select 20 from dual union all
select 20 from dual union all
select 30 from dual
)
select t.*, rank() over (order by score),
count(*) over (order by score range between unbounded preceding and current row)
from t;
我希望是明确的,但是没有窗口子句的order by
的默认值为range between
(我认为这是ANSI标准行为,在我测试过的四个数据库上都是如此),因此您可以删除它:
select t.*, rank() over (order by score),
count(*) over (order by score)
from t;