思路:要求是所有课程成绩均大于80以上的学生,则只要一门成绩小于80,就不满足条件。
显然,只要先查出有成绩小于80的学生,然后将其排除掉,那么剩下的即为所有课程成绩都大于80的学生。
sql:
select avg(score) from tb_score where name not in (select distinct name from tb_score where score < 80);
①:select distinct name from tb_score where score < 80 ==> 查询出有成绩小于80的学生;
②:where name not in ==> 使用 not in 将有成绩小于80的学生排除掉;
显然,通过①,② 两步,所得到的即为所有课程成绩都大于80的学生。
注:distinct作用为去重,减少不必要的not in 判断