select tag,uid,ranking from (
select tag,uid,
rank()over(partition by tag order by max(score) desc,min(score) desc,uid desc) as ranking from examination_info
join exam_record using(exam_id)
group by tag,uid) t
where ranking between 1 and 3