시험문제 7일차
4. (결과 테스트 해봐야 함)
select deptno, LTRIM (sys_connect_by_path(ename,','),',') ename
from ( select deptno
, ename
, row_number() over (partition by deptno order by deptno) rnum
, count(*) over (partition by deptno ) cnt
from emp
)
where level = cnt
start with rnum = 1
connect by prior deptno = deptno
and prior rnum = rnum - 1
;
-- 답은 이것으로 예상
select a.ename, b.ename
from emp a,
( select mgr, LTRIM (sys_connect_by_path(ename,','),',') ename
from ( select ename
, mgr
, row_number() over (partition by mgr order by empno) rnum
from emp
)
start with rnum = 1
connect by prior mgr = mgr
and prior rnum = rnum - 1
) b
where a.empno = b.mgr
;
5.
select b.aaa, b.saumsal, sum(sumsal) over (order by aaa ) cumulative
from ( select a.aaa , sum(a.sal) sumsal
from ( select to_char(hiredate, 'yyyy') aaa , sal
from emp
) a
group by aaa ) b
;
or
select b.aaa, b.saumsal, sum(sumsal) over (order by aaa rows between unbounded preceding and current row ) cumulative
from ( select a.aaa , sum(a.sal) sumsal
from ( select to_char(hiredate, 'yyyy') aaa , sal
from emp
) a
group by aaa ) b
;
--- 그러나
select to_char(hiredate, 'yyyy') aaa, sal
from emp
group by to_char(hiredate, 'yyyy')
;
이게 만약 가능하다면
select b.aaa, b.saumsal, sum(sumsal) over (order by aaa ) cumulative
from ( select to_char(hiredate, 'yyyy') aaa , sum(a.sal) sumsal
from emp
group by to_char(hiredate, 'yyyy') ) b
;
'ORACLE > SQLP' 카테고리의 다른 글
2016년 4월달 SQLP 시험 실기 (0) | 2016.11.25 |
---|---|
SQLP 시험문제 11일차 (0) | 2016.11.24 |
SQLP 시험문제 6일차 (0) | 2016.11.24 |
sqlp19회 실습문제 2번 테이블명 컬럼명 영어로 바꿈 (0) | 2016.11.04 |
sqlp 19회 실습문제 2번 테스트 테이블 작성 (0) | 2016.11.04 |