查询满足条件的元组可以通过where子句实现。其常用的查询条件如下
查询条件 谓词
比较 =, >, <, <=, !=, <>, !>,!<; not + 上述比较运算符
确定范围 between and , not between and ,
确定集合 in , not in
字符匹配 like, not like
空值 is null, is not null
多重条件 and , or
(1)比较大小
例7:查询计算机系全体学生的名单
select sname
from student
where sdept='cs'
例8:查询所有年龄在20岁以下的学生姓名及其年龄
select sname,sage
from student
where sage<20
可以这样写:
select sname,sage
from student
where not sage>=20
例9:查询考试成绩有不及格的学生的学号
select distinct sno
from sc
where Grade < 60
(2)确定范围
例10:查询年龄在20~23岁(包括20岁和23岁)之间的学生的姓名、系别和年龄
select sname, sdept,sage
from student
where sage between 20 and 23
例11:查询年龄不在20~23岁之间的学生的姓名、系别和年龄
select sname, sdept,sage
from student
where sage not between 20 and 23