select tag, difficulty, round(avg(score),1) from( select tag, difficulty, score, row_number()over(order by score) a, row_number()over(order by score desc) b from exam_record left join examination_info using(exam_id) where tag='SQL' and difficulty='hard' and score is not null) as tb1 where a!=1 and b!=1 group by tag, difficulty