WITH t AS ( SELECT uid, tag, max( score ) AS da, min( score ) AS xiao FROM exam_record left join examination_info using(exam_id)where score is not null GROUP BY 1, 2 order by 2,3 desc ) select * from( SELECT tag, uid, row_number() over ( PARTITION BY tag ORDER BY da DESC, xiao DESC, uid DESC ) AS ranking FROM t ) tmp where ranking<=3

京公网安备 11010502036488号