- 在查询条件的位置作为条件存在
在查询条件的位置作为条件存在
A.使⽤in
Eg1:查询考试不及格的学⽣名单
B.使⽤not in
Eg2:查询没有参加基于C语⾔理解软件编程考试的学⽣名单
– A.使用in
– Eg1:查询考试不及格的学生名单
select studentid from exam where exam<60
select * from studentinfo where studentid in(
select studentid from exam where exam<60
)
– B.使用not in
– Eg2:查询没有参加基于C语言理解软件编程考试的学生名单
select * from subject where subjectname=‘基于C语言理解软件编程’
select studentid from exam where subjectid=1
select * from studentinfo where studentid not in(
select studentid from exam where subjectid=(
select subjectid from subject where subjectname=‘基于C语言理解软件
编程’) )
C.使⽤all
Eg3:查询成绩⽐“C003”这⻔课程的任意成绩都⼤的学⽣考试信息。
D.使⽤any
Eg4:查询成绩⽐“C003”这⻔课程的某⼀个成绩⾼的学⽣考试信息
C.使用all:所有>all(子查询,返回值是多行一列),
如果值大于子查询结果中的所有才算true应该被显示否则不显示:>max Eg3:查询成绩比“基于C语言理解软件编程”这门课程的所有人成绩都大的学生考试信息。
select * from `subject` where subjectname='基于C语言理解软件编程' select * from exam where subjectid=1 select * from exam where exam>all( select exam from exam where subjectid=( select subjectid from `subject` where subjectname='基于C语言理解软件 编程')); select * from exam where exam>( select max(exam) from exam where subjectid=( select subjectid from `subject` where subjectname='基于C语 言理解软件编程')) -- D.使用any:任意,>any(子查询) :大于子查询中任意一个值即可,>min -- Eg4:查询成绩比“C003”这门课程的某一个成绩高的学生考试信息 select * from exam where exam>any( select exam from exam where subjectid=( select subjectid from `subject` where subjectname='基于C语言理解软件 编程' ); select * from exam where exam>( select min(exam) from exam where subjectid=( select subjectid from `subject` where subjectname='基于C语 言理解软件编程' ) );



