oracle 高级查询
Oracle高级查询使用Oracle特有的查询语法, 可以达到事半功倍的效果1. 树查询create table tree ( id number(10) not null primary key, name varchar2(100) not null, super number(10) not null // 0 is root);-- 从子到父select * from tree start with id = ? connect by id = prior super -- 从父到子select * from tree start with id = ? connect by prior id = super-- 整棵树select * from tree start with super = 0 connect by prior id = super2. 分页查询select * from ( select my_table.*, rownummy_rownum from ( select name, birthday from employee order by birthday ) my_table where rownum < 120 ) where my_rownum >= 100;3. 累加查询, 以scott.emp为例select empno, ename, sal, sum(sal) over(order by empno) result from emp; EMPNO ENAME SAL RESULT---------- ---------- ---------- ---------- 7369 SMITH 800 800 7499 ALLEN 1600 2400 7521 WARD 1250 3650 7566 JONES 2975 6625 7654 MARTIN 1250 7875 7698 BLAKE 2850 10725 7782 CLARK 2450 13175 7788 SCOTT 3000 16175 7839 KING 5000 21175 7844 TURNER 1500 22675 7876 ADAMS 1100 23775 7900 JAMES 950 24725 7902 FORD 3000 27725 7934 MILLER 1300 290254. 高级group byselect decode(grouping(deptno),1,'all deptno',deptno) deptno, decode(grouping(job),1,'all job',job) job, sum(sal) salfrom emp group by ROLLUP(deptno,job);DEPTNO JOB SAL---------------------------------------- --------- ----------10 CLERK 130010 MANAGER 245010 PRESIDENT 500010 all job 875020 CLERK 190020 ANALYST 600020 MANAGER 297520 all job 1087530 CLERK 95030 MANAGER 285030 SALESMAN 560030 all job 9400all deptno all job 290255. use hint当多表连接很慢时,用ORDERED提示试试,也许会快很多SELECT /*+ ORDERED */* FROM a, b, c, dWHERE
页:
[1]