找出所有课程高于80分的学生

有2个表   学生表(Student)  成绩表(grade)

 

一、方法1 反向求解

可以从反面求解,只要有一门课程不满足条件,则该学生不再考虑   select distinct g.no from grade g where g.socre<80

 

然后在学生表中反向求解学生 ,条件为学号不在上面查询的集合中的  

select t.name,t.no from student t where t.no not in (
select distinct g.no from grade g where g.socre<80)  

 

 

 二、方法2  使用having min()与group by 

select m.name from (  select t.name, t.no, g.class_no, g.socre

from student t
  left join grade g
    on g.no = t.no) m
    group by m.name
having min(m.socre)>= 83

三、方法3  使用 not exist 


select *
from student t
where t.no not in (select distinct a.no
from grade a
where not exists (select 1
from grade b
where b.socre < 80
and b.no = a.no))

 

posted @ 2021-06-16 22:23  凉了记忆  阅读(434)  评论(0编辑  收藏  举报