Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calculate Running Average

0 views
Skip to first unread message

Arijit Chatterjee

unread,
Jul 2, 2003, 11:07:50 PM7/2/03
to
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

Ian D. Bjorhovde

unread,
Jul 3, 2003, 12:51:42 AM7/3/03
to

You can use windowing functions:

select col1, col2, avg(col2) over (order by col1)


Good luck,

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----

Arijit Chatterjee

unread,
Jul 3, 2003, 10:36:24 PM7/3/03
to
arijitcha...@yahoo.co.in (Arijit Chatterjee) wrote in message news:<ea01504d.03070...@posting.google.com>...

Thanks Lan Your answer is working perfectly.
Arijit Chatterjee

0 new messages