假设用户成绩表为t_score,其中c_userid为用户ID,c_score为该用户得分 t_score -------------------- c_userid c_score -------------------- 131 85 126 79 147 90 113 85则 select to_char(a.c_userid) || ',恭喜你是第' || to_char(a.c_rank) || '名!' from ( select c_userid, rank() over (order by c_score) c_rank from t_score ) a where a.c_userid = (用户ID)
select name,decode(rk,1,'恭喜你是第1名',2,'恭喜你是第2名',3,'恭喜你是第3名') 名次 from (select name,rank() over(order by score DESC) rk from talbe_name) order by score DESC
select c_userid,decode(rownum,ROWNUM,'共恭喜你得了'||rownum||'名') from talbe_nameorder by c_score desc;
我就是想知道如何得到用户的名次呢?
t_score
--------------------
c_userid c_score
--------------------
131 85
126 79
147 90
113 85则
select to_char(a.c_userid) || ',恭喜你是第' || to_char(a.c_rank) || '名!'
from ( select c_userid, rank() over (order by c_score) c_rank from t_score ) a
where a.c_userid = (用户ID)
from
(select name,rank() over(order by score DESC) rk from talbe_name)
order by score DESC