Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Dynamic calculation
"Alex" <dead.man.walking_at_gmx.de> a écrit dans le message de news: 1159426319.105263.113830_at_h48g2000cwc.googlegroups.com... Michel Cadot schrieb:
> <dead.man.walking_at_gmx.de> a écrit dans le message de news: 1159370526.506812.111470_at_m7g2000cwm.googlegroups.com...
> > Don't top-post. > > You did not read enough the doc. It's basic analytical functions. > > SQL> select month, value, > 2 sum(value) over (order by to_date(month,'Mon')) till_month_value > 3 from t > 4 / > MONTH VALUE TILL_MONTH_VALUE > ---------- ---------- ---------------- > Jan 1000 1000 > Feb 2000 3000 > Mar 800 3800 > Apr 600 4400 > May 1400 5800 > Jun 730 6530 > Jul 970 7500 > > 7 rows selected. > > Regards > Michel Cadot
Due to not testing the long form (BETWEEN ... AND ...) my attempts
failed.
I thought the short form is equivalent and produces identical results
as the long form.
Obvious, that's not right.
Thank you for enlighting my way!
Alex Sauer
All these forms are equivalent and return the same values:
SQL> select month, value,
2 sum(value) over (order by to_date(month,'Mon') 3 range between unbounded preceding and current row) till_month_value4 from t
---------- ---------- ---------------- Jan 1000 1000 Feb 2000 3000 Mar 800 3800 Apr 600 4400 May 1400 5800 Jun 730 6530 Jul 970 7500
7 rows selected.
SQL> select month, value,
2 sum(value) over (order by to_date(month,'Mon') 3 range unbounded preceding) till_month_value4 from t
---------- ---------- ---------------- Jan 1000 1000 Feb 2000 3000 Mar 800 3800 Apr 600 4400 May 1400 5800 Jun 730 6530 Jul 970 7500
7 rows selected.
SQL> select month, value,
2 sum(value) over (order by to_date(month,'Mon')) till_month_value
3 from t
4 /
MONTH VALUE TILL_MONTH_VALUE
---------- ---------- ---------------- Jan 1000 1000 Feb 2000 3000 Mar 800 3800 Apr 600 4400 May 1400 5800 Jun 730 6530 Jul 970 7500
7 rows selected.
Regards
Michel Cadot
Received on Thu Sep 28 2006 - 10:49:56 CDT
![]() |
![]() |