题解 | #SQL类别高难度试卷得分的截断平均值#
SQL类别高难度试卷得分的截断平均值
http://www.nowcoder.com/practice/a690f76a718242fd80757115d305be45
截取最大值和最小值,只需要使用score的全部和-最大值-最小值,再除以score个数-2即可 使用GROUP BY 对difficulty进行分组,只选择困难程度为hard的数据
SELECT
ei.tag,
ei.difficulty,
ROUND((SUM(er.score) - max(er.score)-min(er.score)) / (COUNT(er.score) - 2) ,1)AS clip_avg_score
FROM examination_info AS ei
LEFT JOIN exam_record AS er
ON ei.exam_id = er.exam_id
WHERE ei.difficulty = "hard" AND tag = "SQL"
GROUP BY ei.difficulty