在from字句中使用子查询
如何显示高于自己部门平均工资的员工的信息
select a2.ename,a2.sal,a2.deptno,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
内嵌视图时,必须制定别名
分页查询
一共有三种方式
1.rownum分页
select * from (select al.*,rownum rm from (select * from emp) a1 where rownum <=10) where rm >=6;
几个查询的变化:
a.指定查询列,只需改最里面的查询即可
b。排序,也只需在最里面的查询即可
显示第4-9的语句
第二种:根据rowid来分 效率最高
select * from t.xiaoxi where rowid in(select rid from (select rownum rm,rid from (select rowid rid ,cid from t.xiaoxi order by cid desc) where rownum<10000)where rn>9980) order by cid desc;
用查询结果创建新标
这个命令是一种快捷的见表方式
create table mytable(id,name,sal,job,deptno) as select empno,ename,sal,job ,deptno from emp;
合并查询
本文介绍SQL中的高级查询技术,包括使用子查询展示部门内工资高于平均水平的员工信息、实现分页查询的不同方法以及通过查询结果快速创建新表的实用技巧。
57

被折叠的 条评论
为什么被折叠?



