#三.条件查询
条件查询:是用户按照一定条件查询,查询满足条件的部分记录
语法:select 查询内容 from 表 where 条件
1.比较运算符的使用
= >< >= <= != <>
例如:查询部门号为20的雇员信息
select * from emp where deptno =20
例如:查询薪资大于等于3000的雇员信息
select * from emp where sal>=3000
例如:查询薪资小于等于3000的雇员名称,薪资,职位按照薪资升序排序
select ename,sal,job from emp where sal<=3000 order by sal asc
例如:查询雇员的姓名为smith的雇员信息
select * from emp where ename ='smith'
或者
select * from emp where ename ='SMITH'
注意:mysql默认的是不区分大小写,如果需要区分大小写,
则可以使用binary关键字
例如:查询雇员的姓名为smith的雇员信息
select * from emp where binary ename ='smith'
select * from emp where binary ename ='Smith'
2.[not]between and 的使用可以查询某区间范围的记录
例如:查询薪资在1200-3000之间的雇员信息
select * from emp where sal between 1200 and 3000
例如:查询薪资不在1200-3000之间的雇员姓名,薪资
select ename,sal from emp;
where sal not between 1200 and 3000
order by sal asc
3. [not]in 表示在指定集合中
语法: select 查询内容 from 表名 where 字段名 in(值1,值2....)
列如:查询雇员姓名是smith,scott,king的雇员信息
select * from emp where ename in('smith','scott','king')
列如:查询雇员姓名不是smith,scott,king的雇员信息
select * from emp where ename not in ('smith','scott','king')