时间:2021-07-01 10:21:17 帮助过:4人阅读
select level, lpad(‘ ‘,2 * level - 1) || ename as "Ename", job from emp start with ename = ‘SCOTT‘ connect by prior empno = mgr;
--从下向上遍历(交换connect by prior中的条件即可,使用mgr = empno) --注意connect by prior mgr = empno 的理解 --prior表示前一条记录,即下一条返回记录的empno应当等于前一条记录的mgr
select level, lpad(‘ ‘,2 * level - 1) || ename as "Ename", job from emp start with ename = ‘SCOTT‘ connect by prior mgr = empno;
select level, lpad(‘ ‘,2 * level - 1) || ename as "Ename", job from emp start with ename = ‘SCOTT‘ connect by empno = prior mgr;
select level, lpad(‘ ‘,2 * level - 1) || ename as "Ename" ,job from emp where ename != ‘SCOTT‘ --通过where子句来过滤SCOTT用户,但SCOTT的下属ADAMS并没有过滤掉 start with empno = 7839 connect by prior empno = mgr;
select level, lpad(‘ ‘,2 * level - 1) || ename as "Ename" ,job from emp start with empno = 7839 connect by prior empno = mgr and ename != ‘SCOTT‘;
select level, lpad(‘ ‘,2 * level - 1) || ename as "Ename" ,job from emp where sal > 2500 start with empno = 7839 connect by prior empno = mgr;
select level, lpad(‘ ‘,2 * level - 1) || ename as "Ename" ,job from emp where sal > (select avg(sal) from emp) start with empno = 7839 connect by prior empno = mgr ;
08.SQL基础-->层次化查询(START BY ... CONNECT BY PRIOR)
标签:rom png 等于 sel start evel 技术 images image