时间:2021-07-01 10:21:17 帮助过:28人阅读
数据库的执行sql是 从左到右 select deptno,avg(sal) mysal from emp group by deptno; select a2.ename,a2.sal,a1.mysal from emp a2 ,( select deptno,avg(sal) mysal from emp group by deptno ) a1 where a2.deptno=a1.deptno and a2.sala1.mysal;(a1、a
数据库的执行sql是 从左到右
select deptno,avg(sal) mysal from emp group by deptno;
select a2.ename,a2.sal,a1.mysal from emp a2,(select deptno,avg(sal) mysal from emp group by deptno) a1 where a2.deptno=a1.deptno and a2.sal>a1.mysal;(a1、a2为表别名,黄色填充部分也称为内嵌视图)
注意: 给表取别名时别名前面不可加as,列取别名时可加可不加
***1.rownum分页(常用)
select * from(select a1.*,rownum rn from (select * from emp) a1 where rownum<=10) where rn>=6;
若要指定查询列,只需修改最里层的视图,例如:
select * from(select a1.*,rownum rn from (select * from emp order by sal) a1 where rownum<=10) where rn>=6;
***2. 根据rowid(效率最高)
***3.按分析函数来分页(效率最差)
这种方法可把emp表中数据导入到新建mytable表中
select ename,sal,job from emp where sal>2500 union
select ename,sal,job from emp where job=‘MANAGER’;
集合图展示:
集合图展示:(a集合减去b集合)
*****************集合操作效率远远高于”or“"and"等***************************