select uid,t3.exam_id,round(avg((score - min_score)/(max_score - min_score) * 100),0) as avg_new_score from exam_record t3 join ( select t1.exam_id,max(score) as max_score,min(score) as min_score from examination_info t1 join exam_record t2 on t1.exam_id = t2.exam_id where difficulty = 'hard' group by t1.exam_id having count(score) > 1 ) t4 on t3.exam_id = t4.exam_id where t3.score is not null group by uid,t3.exam_id union all select max(uid),exam_id,max(score) as avg_new_score from exam_record group by exam_id having count(score) = 1 order by exam_id,avg_new_score desc