计算不得小于平均分的最低分数,要点就在于如何将分数与平均分做比较,此处比较推荐在where字句中进行条件判断,虽然在where子句中使用select查询会降低查询效率,但只要数据量不大,也是可以使用的。
select min(e1.score) min_score_over_avg from exam_record e1 join examination_info e2 on e1.exam_id=e2.exam_id where tag='SQL' and e1.score >= (select avg(score) from exam_record e3 join examination_info e4 on e3.exam_id=e4.exam_id where e4.tag="SQL");

京公网安备 11010502036488号