cf.) Analytic function(=Window function)을 사용하면 쉽게 구할 수 있습니다.
drop table test purge;
create table test
as
select empno, sal
from emp
where rownum <= 3;
- 원하는 결과는 아래와 같습니다.
EMPNO SAL 누적합
---------- ---------- -------
7369 800 800
7499 1600 2400
7521 1250 3650
select * from test;
select t1.empno, t1.sal, t2.empno, t2.sal
from test t1 join test t2
on (t1.empno >= t2.empno)
order by 1;
↓ ↓ ↓
select t1.empno, t1.sal, sum(t2.sal) as 누적합
from test t1 join test t2
on (t1.empno >= t2.empno)
group by t1.empno, t1.sal
order by t1.empno;
* Analytic function (Window function) 을 이용한 해법
==> http://goo.gl/iMTAz
select empno, sal
, sum(sal) over (order by empno) as 누적합
from test;
'Oracle > SQL Fundamentals I' 카테고리의 다른 글
9일차 # 6-6: Guideline (0) | 2012.04.16 |
---|---|
9일차 # 6-1 Subquery(inner query) (0) | 2012.04.16 |
9일차 퀴즈~ (0) | 2012.04.16 |
8일차 # 5-26: CROSS JOIN (Cartesian Product) (0) | 2012.04.13 |
8일차 # 5-25: FULL OUTER JOIN (0) | 2012.04.13 |