思路:将表中各科目的最大值和最小值选出组合,然后筛选出分数值不是最值表中的 可以确保所有的最大值和最小值排除,避免出现多人同为未全部排除的情况

select ei.tag,ei.difficulty,round(avg(er.score),1) as clip_avg_score
from exam_record er left outer join examination_info ei
    on er.exam_id=ei.exam_id
where er.score is not null
  and er.score not in (select max(score) from exam_record e
                      group by e.exam_id
                      union
                      select min(score) from exam_record
                     group by exam_id
                    )
group by er.exam_id
-- having count(ei.exam_id)>=3