MySQL条件查询

9.3 条件查询 Where

9.3.1常见的运算符

关系运算符:=!=<>>=<=

区间:between A an B -[ A,B ]

And :并且,和、

Or: 或者

Is null : 空

Not:否,非

Is not null:非空

In:在什么里面

9.3.2or、并且and

 

 

查询性别女,并且 年龄65的记录

Select * from stu where gender =’female’ and age=65;

查询学号是S_1001或者名字为LiSi的记录

Select * from stu where sid = ‘S_1001’  or  sname=’LiSi’;

 

9.3.3在什么里面in

 

查询学号是S_1001,S_1002,S_1003的记录

(1)

Select * from  stu where sid = ‘S_1001’ or sid =‘ S_1002’ or sid = ‘S_1003’;

(2)

Select * from  stu where sid in(‘S_1001‘,‘S_1002‘,‘S_1003‘);

 

9.3.4是否为空is notnull

 

查询学号不是S_1001,S_1002,S_1003的记录

Select * from  stu where sid not in(‘S_1001‘,‘S_1002‘,‘S_1003‘);

 

查询年龄是null的记录

Select * from  stu where  age is null

 

查询名字不为空的学生信息

Select * from  stu where sname is not null;

9.3.5区间 between

查询年龄是2040之间的年龄

Select * from  stu where age>=20 and age <=40;

Select * from stu where age between 20 and 40;

9.3.6not

查询性别:非男的 学生记录

(1)

Select * from stu where gender != ’male’;

(2)

Select * from stu where gender <> ’male’;

(3)

Select * from stu where not gender = ‘male’;

 

MySQL条件查询

上一篇:Linux安装 Java + MySQL + Redis


下一篇:Spring 4 Jasper Report integration example with mysql database in eclipse