题解 | #每类试卷得分前3名#
每类试卷得分前3名
http://www.nowcoder.com/practice/255aa1863fe14aa88694c09ebbc1dbca
select tag, uid, ranking
from(
select tag, e_r.uid,
row_number() over (partition by tag order by max(score) desc, min(score) desc, e_r.uid desc) as ranking
from exam_record e_r join examination_info e_i
on e_r.exam_id = e_i.exam_id
group by tag, e_r.uid
) t
from(
select tag, e_r.uid,
row_number() over (partition by tag order by max(score) desc, min(score) desc, e_r.uid desc) as ranking
from exam_record e_r join examination_info e_i
on e_r.exam_id = e_i.exam_id
group by tag, e_r.uid
) t
where ranking <= 3