select *
from
(select tag,uid,ROW_NUMBER()over(partition by tag order by max(score) desc,min(score) desc,uid desc) as ranking
from examination_info t
join exam_record t1 on t.exam_id = t1.exam_id
group by tag,uid) t1
where ranking <=3