过滤 和 排序
1. 过滤: 也就是给查询以 where 条件 滤去不需要部分
----select * from emp where deptno = 10;
------where后面可以是多个字段取交集 但是只能是单行函数。
2. and , or , in , not in , between and , < , >
--where ename ='KING' and job = 'PRESIDENT' --and表示同时满足
--where deptno = 20 or deptno = 10 --or表示两者满足一个都可以 10,20 都取
--where deptno in (10,20) --同 or 取并集 deptno=10 or deptno=20
--where deptno not in (20,30) --同and 取交集 !=20 and != 30
--where sal between 2000 and 5000 --区间值 只能小在前 大在后
--where sal > 2000 and sal < 5000
3. 模糊查询 like %
--select * from emp where ename like '%o%';
--查询员工名字中有 o 的所有员工信息
--like 是一个关键字 表示模糊查询,其中的% 代表通配
--where ename like 'K%' --ename 中以K 开头的员工
--where ename like '____' --ename字符串长度为四的员工信息
--在oracle 中 _ 代表一个字符
--where ename like '%\_%' escape '\'; --oracle 中的转义
4. 优化 where 条件的优化
--where 语句是从右往左执行的
--where deptno =10 and ename like '%a%' 中赢注意将省略更多的放在右边
5. 排序 order by
-- select * from emp order by sal; --根据员工的sal 排序(默认为升序)
--order by sal desc 降序排列 desc 只作用于离他最近的那个字段
--order by sal asc 升序排列
--order by deptno,empno desc; --如果排序后面跟了多个列,那么会首先使用第一列来排,第一列拍出来的,使用第二列来拍,以此类推。
--select emono,deptno,sal*12 + nvl(comm,0) from emp order by 3; 按照select 后的第三个字段 排序
--在oracle 中排序 null 是最大的
--order by comm desc nulls last; --让null 在最后显示。