常用的查询条件
比较
“=”、“<”、“>”、“<=”、“>=”、“!=”、“!>”、“!<”、“not + 运算符”
select distinct sname
from student
where sdept='cs'
多重条件
“and”、“or”、“not”
select distinct sname
from student
where sage>20 and sdept='cs'
确定范围
“between and”、“not between and”,范围是闭区间
select distinct sname, sage
from student
where sage between 20 and 21
确定集合
“in()”、“not in()”
用 “in()” 可以用来查找属性值属于指定集合的元组
select distinct sname, sage
from student
where sdept in('cs','is')
字符匹配
通配符“%”
“%”可匹配任意长度的字符串
select distinct sname, sage
from student
where sname like '爱%青菜'
通配符“_”
“_”代表任意单个字符
select distinct sname, sage
from student
where sname like '王_'
转义字符“\”
这是MySQL的写法,和java转义一样
select distinct sname, sage, sdept
from student
where sdept like 'cs\_%'
空值查询
“is null”、“is not null”
select distinct sname, sage, sdept
from student
where sage is null