条件查询where
9.3.1常见的运算符
关系运算符:=、!=、<>、>=、<=
区间:between A and B -》[A,B]
And :并且,和。
Or:或者
Is null:空
Not:否,非
Is not null:非空
In:在什么里面
9.3.2 或or、并且and
##(2.1)查询性别女,并且 年龄65的学生记录
select * from stu where gender='female' and age='65';
##(2.2)查询学号是S_1001或者名字为liSi的记录。
select * from stu where sid='S_1001' or sname='liSi';
9.3.3 (不)在什么里面in
##(2.3)查询学号是S_1001,S_1002,S_1003的记录
写法一:select * from stu where sid='S_1001' or sid='S_1002' or sid='S_1003';
写法二:select * from stu where sid in('S_1001','S_1002','S_1003');
##(2.4)查询学号不是S_1001,S_1002,S_1003的记录
select * from stu where sid not in('S_1001','S_1002','S_1003');
9.3.4 是否为空 is (not) null
##(2.5)查询年龄为null的记录
select * from stu where age is null;
##(2.6)查询名字不为空的学生信息
select * from stu where sname is not null;
9.3.5 区间between
##(2.7)查询年龄为20~40岁之间的
方法一:select * from stu where age >= 20 and age <= 40;
方法二:select * from stu where age between 20 and 40;
9.3.6 非not
##(2.8)查询性别:非男的 学生记录
方法一:select * from stu where gender != 'male';
方法二:select * from stu where gender <> 'male';
方法三:select * from stu where not gender = 'male';