题解 | #牛客每个人最近的登录日期(四)#
考试分数(三)
http://www.nowcoder.com/practice/b83f8b0e7e934d95a56c24f047260d91
select t.id,b.name,t.score
from language b,
(select *,dense_rank() over(partition by language_id order by score desc) t_rank from grade) t
where t_rank<=2 and b.id=t.language_id order by b.name,t.score desc,t.id asc
from language b,
(select *,dense_rank() over(partition by language_id order by score desc) t_rank from grade) t
where t_rank<=2 and b.id=t.language_id order by b.name,t.score desc,t.id asc
天呀,我说的嘛,为啥写了很久查出来的数据不对,是因为排序时是按score升序排列的,而不是降序!