oracle中表连接查询 和 分页查询
来源:互联网 发布:淘宝网上怎么开店铺 编辑:程序博客网 时间:2024/06/08 10:28
1 . 自连接
解释 : 自连接是指在同一张表的连接查询 。
例子 : select worker.ename,boss.ename from emp worker,emp boss where worker.mgr=boss.empno and worker.ename='FORD';
子查询 : 指的就是嵌套查询 ;
例子:select ENAME,DEPTNO from emp where deptno = (select DEPTNO from emp where ename = 'SMITH');
子查询包含单行子查询(第二个select语句返回一个结果) 和多行子查询(返回多个结果) ;
在子查询中使用all关键字;
select * from emp where sal > all(select sal from emp where deptno = 30);
在子查询中使用any关键字;
select * from emp where sal > any(select sal from emp where deptno = 30);
多列子查询:
select * from emp where (deptno,job) = (select deptno,job from emp where ename='SMITH' );
复杂的查询:
select * from emp a1,(select deptno,avg(sal) mysal from emp group by deptno) a2
where a1.deptno=a2.deptno and a1.sal>a2.mysal;
记住给表区别名的时候不能使用as关键字 但是列可以 加as
-----------------------------------------------------------------------------------------
oracle的分页 一共有三种方式 :
假如我要查询 数据库中 5 - 10 的记录
第一步: 使用rownum 分页:
select emp1.* ,rownum from (select * from emp) emp1;
其中的 rownum 是oracle本身分配的;
第二步:select emp1.* ,rownum from (select * from emp) emp1 where rownum<=10;
第三步 :
select * from (select emp1.* ,rownum rn from (select * from emp) emp1 where rownum<=10) emp2 where rn>=5;
一定要记得 给 rownum 取别名; 要不然是查不出数据的;
如果要对某个字段进行排序 只需要改动 最底层的select 语句select * from emp 只需改这个语句:
例如 : 我们要对emp表的sal 进行降序排
select * from (select emp1.* ,rownum rn from (select sal,ename from emp order by sal desc) emp1 where rownum<=10) emp2 where rn>=5;
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
怎样用查询结果去创建表,这种命令是一种快捷的建表方法:
create table mytable(id,name,sal,job,deptno) as select empno,ename,sal,job,deptno from emp;
集合操作符为了合并 多个select语句的查询出来的结果
union (联合)
该操作符用于取得 两个结果集的并集 。当使用该操作符时, 会自动去掉重复结果集中的重复行
intersect(交集)
select * from emp where sal >1500 intersect select * from emp where JOB = 'MANAGER';
minus(差集)
select * from emp where sal >1500 minus select * from emp where JOB = 'MANAGER';
- oracle中表连接查询 和 分页查询
- Oracle中表的连接方式查询讲解
- oracle查询中表的连接顺序 手工指定
- php连接oracle类 分页查询和乱码问题
- mysql 和oracle分页查询
- 数据库中表的复杂查询&分页
- oracle Oracle分页查询
- oracle查询语句、分页查询
- oracle中表查询需要注意的常见问题
- 分页查询 Oracle 和 mySql的不同:
- Oracle和SQL 2008分页查询
- Mysql和Oracle数据库中的分页查询
- 详解Oracle和SQLServer的分页查询
- Oracle ROWNUM用法和分页查询总结
- sql server2005和oracle分页查询语句
- Oracle、MYSQL、sqlserver和DB2分页查询
- Oracle ROWNUM用法和分页查询总结
- Oracle ROWNUM用法和分页查询总结
- oracle中关键字的使用
- CPropertyPage::OnSetActive()和OnKillActive()函数:属性页切换时的处理函数
- android 语言设置
- 我打算开始写博客了!
- android 语言设置2
- oracle中表连接查询 和 分页查询
- C#中ToString格式大全
- java的日期互转
- mvn命令和pom的使用
- EXC_BAD_ACCESS
- First
- all和any的区别测试
- Hibernate核心接口和类
- Android RIL源码研究笔记 の ril_command (一)