create table if not exists busi.user_rank
(
uname varchar(200),
score int
);
comment on column busi.user_rank.score is '得分';
insert into busi.user_rank (uname, score) values ('小明',88);
insert into busi.user_rank (uname, score) values ('小王',88);
insert into busi.user_rank (uname, score) values ('小刘',98);
insert into busi.user_rank (uname, score) values ('小张',70);
insert into busi.user_rank (uname, score) values ('小张',null);
select uname,
score,
rank() over (order by score desc nulls last )
from busi.user_rank
小刘 98 1
小明 88 2
小王 88 2
小张 70 4
小张 5
select uname,
score,
row_number() over (order by score desc nulls last )
from busi.user_rank;
小刘 98 1
小明 88 2
小王 88 3
小张 70 4
小张 5