오라클 계층형 쿼리
●계층형 쿼리 - 계층 관계가 있는 칼럼(외래키로 자기자신 테이블을 참조)이 있는 경우 계층 구조를 이용하여 데이터를 추출- 형식select 칼럼from 테이블start with 조건connect by [prior] [nocycle] ex)select empno, ename, mgr, connect_by_root ename, sys_connect_by_path(ename, '/')from empstart with mgr is nullconnect by prior empno = mgr; arex)select level,lpad(' ',(level-1)*2,' ')||ename, sal,deptnofrom empstart with ename = 'KING'connect by prior empno = mgr;
2015. 9. 2.
오라클 select, distinct, group by having, order by
●select 칼럼명 from 테이블명;- 칼럼명부문에 웬만하면 * 를 사용하지 말고 칼럼명을 적어주는게 좋다(서버 부하를 줄이기 위해)ex)select deptno from emp; ●distinct- 컬럼에서 중복을 제거하고 같은 값이면 하나만 출력한다.ex)select distinct(deptno) from emp; ●group by- 특정 칼럼을 기준으로 한 그룹으로 묶어서 합계, 평균, count 등에서 사용한다.ex)select deptno, avg(sal), sum(sal) from empgroup by deptno; ●having- group by 기준 칼럼,그룹핑 함수에 조건을 건다.ex)select deptno, avg(sal), sum(sal) from empgroup by deptn..
2015. 8. 28.