1、比较运算符
2、其他比较运算符
BETWEEN ... AND... //两个值之间包含边界
in (set) //等于列表中的一个值
select * from emp where deptno (not) in(10,20);
如何集合中有空值,不能使用not in,但是可以使用in
not in(10,20,null) //不可以
in (10,20 null)//可以
LIKE //模糊查询
IS NULL //空值
3、like 中的“_”表示一个字符和“%”表示任意个字符
select * from emp where ename like 'S%';//查看S开头的
select * from emp where ename like '_';//查询只有一个字符长度
查询字符串中含有下划线_的数据:使用转义字符
select * from emp where ename like "%\_%" escape '\';
4、oracle自动开启事务,可以直接使用rollback,而在mysql中需要手动开启:start transcation
5、where 语句的解析顺序是从右到左的
当where后有and时,尽量将可能为假的条件放在右边
当where后有or时,尽量将可能为真的条件放在右边
可以起到SQL优化的作用
6、Order by + 列、表达式(sal*12)、别名、序号(从1开始,第几列),默认升序
select * from emp order by sal desc;
select ename,sal,sal *12 年薪 from emp order by 年薪
select ename,salsal*12 年薪 from emp order by 3;
上面两个效果相同
7、多个列的排序
select * from emp order by deptno,sal;//先按第一列排序,第一列相同再按第二列排序
select * from emp order by septno ,sal desc;
//先按第一列升序排列,再按第二列降序排列
desc只作用于离它最近的那一列,如果每一列都要降序排列,那么每一列都要使用desc
8、空值的排序
升序时空值的行会排在最后
降序时空值的行会排在最前面,原因是oracle 中空值最大
select *
from emp order by comm desc
nulls last