473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

analytical functions

Hi,
I have a doubt regarding a calculation by using analytical functions.

((1+r1)+(1+r2)+(1+r3)+....(1+r n) )*1000

where r1,r2,r3 are the values of a column in my table.
I need to get the values like this

first row (1+r1)*1000
secondrow ((1+r1)+(1+r2))*1000
.
.
.
.
nth row ((1+r1)+(1+r2)+(1+r3)+....(1+r n) )*1000

suppose you take the table as below

FUNDCODE FUNDRETURNS TIMEKEY

F1 10 200
F1 20 300
F1 40 400
F1 20 500
F1 3 600
F1 60 700
F1 70 800
F1 85 900
F1 90 1000
F1 23 1001


after applying the query
Expand|Select|Wrap|Line Numbers
  1.  
  2. select a.*,sum((fundreturns+1)*1000) over (partition by fundcode order by timekey) runningtotal from  fund_returns a
  3.  
  4.  
i got the output for the above calculation as
FUNDCODE FUNDRETURNS TIMEKEY RUNNINGTOTAL
F1 10 200 11000
F1 20 300 32000
F1 40 400 73000
F1 20 500 94000
F1 3 600 98000
F1 60 700 159000
F1 70 800 230000
F1 85 900 316000
F1 90 1000 407000
F1 23 1001 431000

Now I need to do a similar type but the calculation(multiplication instead of summation) is
(1+r1)*(1+r2)*(1+r3)*....(1+r n) *1000

Is it doable using analytical funtions ??? if so please throw some light on it.

Thanks in advance
Srinivasan M
Dec 19 '07 #1
3 1685
amitpatel66
2,367 Expert 2GB
Hi Srinivasan,

Welcome to TSDN!!

Please make sure you follow POSTING GUIDELINES every time you post in this forum.

Thanks
MODERATOR
Dec 19 '07 #2
amitpatel66
2,367 Expert 2GB
I am not sure how you get the product using any analytical function but I have done using pipelined functions as shown below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> select * from xyz;
  3.  
  4. FC        FR        TK
  5. -- --------- ---------
  6. F1        10       100
  7. F1        20       200
  8. F1        30       300
  9. F1        40       400
  10.  
  11. SQL> select text from user_source where name = 'RMUL';
  12.  
  13. TEXT
  14. ----------------------------------------------------------------------------------------------------
  15. TYPE rmul IS TABLE OF INTEGER;
  16.  
  17. SQL> select text from user_source WHERE name = 'MULT';
  18.  
  19. TEXT
  20. ----------------------------------------------------------------------------------------------------
  21. FUNCTION mult RETURN rmul PIPELINED IS
  22. res NUMBER:= 1;
  23. BEGIN
  24. FOR I IN (SELECT fr+1 fn FROM xyz) LOOP
  25. res:= res * I.fn * 1000;
  26. PIPE ROW(res);
  27. END LOOP;
  28. return;
  29. END;
  30.  
  31. 9 rows selected.
  32.  
  33. SQL> select * FROM TABLE(mult);
  34.  
  35. COLUMN_VALUE
  36. ------------
  37.        11000
  38.    231000000
  39.    7.161E+12
  40.    2.936E+17
  41.  
  42. SQL> 
  43.  
  44.  
I hope this helps!!
Dec 19 '07 #3
Hi Srinivasn,

I think this will get you what you need (assumes fundreturns is always > 0):

Expand|Select|Wrap|Line Numbers
  1. SELECT   f.fundcode,
  2.          f.fundreturns,
  3.          f.timekey,
  4.          EXP (SUM (LN (f.fundreturns + 1)) OVER (PARTITION BY fundcode ORDER BY timekey))
  5. FROM     fund_returns f
  6. ORDER BY fundcode,
  7.          timekey
Chris
Dec 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: elena | last post by:
I have a test online that measures cognitive style. It determines whether the participant has an intuitive or analytical learning style. It takes about 5 minutes. It's here: http://www.elena.com...
5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
5
by: Yuri G. | last post by:
Hi, I'm trying to come up with a solution to seemingly simple database query, which I'm sure could be done with Oracle9 analytical functions, but somehow the solution is elusive: I have a...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
2
by: Ajitha Devi | last post by:
My record set will look like this ENAme -Part Time- Dept qwe - Y - 10 fjj - N - 10 ghsd - N - 10 How to count using...
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.