Hi all,
.
.
SQL> select * from TEST6152;
A B DD
---------- --- ---------
2 USD 12-DEC-07
30 USD 12-DEC-07
30 USD 12-NOV-07
15 USD 22-NOV-07
65 USD 13-SEP-07
.
.
.
I require this output from the quiery
.
CUR DT SUM(T.A)
--- --------- ----------
USD 30-SEP-07 65
USD 30-NOV-07 110
USD 31-DEC-07 142
.
.
which is basically the cumulative sum
.
Now this is what I tried
.
.
SQL> ed
Wrote file afiedt.buf
1 select t1.curr, t1.dt, sum(t.a) from
2 test6152 t,
3 (
4 select B curr, last_day(trunc(DD)) dt from TEST6152 group by B, last_day(trunc(dd))
5 ) t1
6 where
7 t.b = t1.curr
8 and t.dd < t1.dt
9 group by
10 t1.curr, t1.dt
11* order by 1, 2
SQL> /
.
CUR DT SUM(T.A)
--- --------- ----------
USD 30-SEP-07 65
USD 30-NOV-07 110
USD 31-DEC-07 142
.
.
Now my question is : Is there a better way to do this in SQL coz when I translate the same logic to a bigger table (rows > 3 million) , it gives me a performance issue.
Thanks in advance