SELECT x.student_id, x.student_nameFROM(select t1.student_id,t1.student_name,sum(if( t1.rn=1or t1.rn_desc =1 , 1 ,0 )) as is_not_quitefrom(select a.student_id, a.student_name,b.exam_id,row_number()over(partitionby b.exam_id order by b.score desc ) as rn_desc,row_number()over(partitionby b.exam_id order by b.score ) as rnfrom(select student_id, student_name from leetcode.ex_1412_student) ajoin(select exam_id,student_id,score from leetcode.ex_1412_exam ) b ON a.student_id=b.student_id ) t1 group by t1.student_id,t1.student_name ) x WHERE x.is_not_quite=0;