Ask a Question related to IBM DB2, Design and Development.
-
Arijit Chatterjee #1
Calculate Running Average
Hi everybody.I'm Facing a ploblem to calculate running average.I am
explaining the scenario.
In my table there are two column only
1.Name
2.Marks.
In my query what to show another column with running average.
Example
-------
My table already contains
Col1 Col2
---- -----
a 8
b 6
c 10
d 12
e 20
In my query output I want to show the data like this format
Col1 Col2 Col3
---- ----- ----
a 8 8 (Average of 1st row) means 10/1
b 6 7 (Average of 1st + 2nd rows) means (8+6)/2
c 10 8 (Average of 1st + 2nd + 3rd rows) means (8+6+10)/3
d 12 9 (Average of 1st + 2nd + 3rd + 4th rows) means
(8+6+10+12)/4
e 20 11.2 (Average of 1st + 2nd + 3rd + 4th + 4th rows) means
(8+6+10+12+20)/5
I hope it will be clear to all of you.If any problem in understanding
please let me inform.
Thanks
Arijit Chatterjee
Arijit Chatterjee Guest
-
average days
I have a db with two colums create_date and finish_date. What I would like to do is take the datediff of each row , add them togehter, then divide... -
Calculating a moving average
Hi, I need to calculate a moving average and I would like to do it with SQL, or a Pg function built for this purpose. I'm on Pg 7.4. Is this... -
average using lingo
i need a huge hand with something i need to write a function to calculate the average of a sequence and return the result. however it should only... -
Average Invoice value problem
Hi Jason Make calc_RoundTotal a conditional statement that only shows the round total if the record is not a credit note. Bridget Eley -
Average MB/s read from snapshot
All, I've been monitoring the tablespace snapshot information and been calculating how much MB/s the database reads / tablespace (asynch and... -
Ian D. Bjorhovde #2
Re: Calculate Running Average
On 2 Jul 2003, Arijit Chatterjee wrote:
You can use windowing functions:> Hi everybody.I'm Facing a ploblem to calculate running average.I am
> explaining the scenario.
> In my table there are two column only
> 1.Name
> 2.Marks.
> In my query what to show another column with running average.
>
> Example
> -------
> My table already contains
>
> Col1 Col2
> ---- -----
> a 8
> b 6
> c 10
> d 12
> e 20
>
> In my query output I want to show the data like this format
>
> Col1 Col2 Col3
> ---- ----- ----
> a 8 8 (Average of 1st row) means 10/1
> b 6 7 (Average of 1st + 2nd rows) means (8+6)/2
> c 10 8 (Average of 1st + 2nd + 3rd rows) means (8+6+10)/3
> d 12 9 (Average of 1st + 2nd + 3rd + 4th rows) means
> (8+6+10+12)/4
> e 20 11.2 (Average of 1st + 2nd + 3rd + 4th + 4th rows) means
>
> (8+6+10+12+20)/5
>
select col1, col2, avg(col2) over (order by col1)
Good luck,
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
[url]http://www.newsfeeds.com[/url] - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
Ian D. Bjorhovde Guest



Reply With Quote

