关于排名问题的总结

select rank() over(partition by kemu order by fenshu desc) rk,t.* from abcd t
--当出现并列的情况时,名次会缺失 1 2 2 4 5 5 7
select dense_rank() over(partition by kemu order by fenshu desc) rk,t.* from abcd t
--当出现并列的情况时,名次不会缺失 1 2 2 3 4 4 5
select Row_number() over(partition by kemu order by fenshu desc) rk,t.* from abcd t
--不会出现并列情况,名次自动分 1 2 3 4 5 6 7

create table ABCD
(
STDNAME VARCHAR2(50),
STDID VARCHAR2(30) not null,
KEMU VARCHAR2(50),
FENSHU NUMBER(16)
)
alter table ABCD
add constraint PK primary key (STDID)

insert into abcd (STDNAME, STDID, KEMU, FENSHU)
values ('张三', 'aaa', 'yuwen', 70);

insert into abcd (STDNAME, STDID, KEMU, FENSHU)
values ('李四', 'bbb', 'yuwen', 88);

insert into abcd (STDNAME, STDID, KEMU, FENSHU)
values ('王五', 'ccc', 'yuwen', 45);

insert into abcd (STDNAME, STDID, KEMU, FENSHU)
values ('马六', 'dddd', 'yuwen', 36);

insert into abcd (STDNAME, STDID, KEMU, FENSHU)
values ('赵七', 'eee', 'yuwen', 88);

insert into abcd (STDNAME, STDID, KEMU, FENSHU)
values ('刘八', 'fff', 'yuwen', 45);

insert into abcd (STDNAME, STDID, KEMU, FENSHU)
values ('陈九', 'ggg', 'yuwen', 90);

你可能感兴趣的:(总结)