Link to home
Start Free TrialLog in
Avatar of gigglick
gigglick

asked on

(100 pts)Geometric to Harmonic mean

Hello everyone.
 I have recently been computing the geometric mean of a column in out SQL Server 2000 DB using the following script:
 exp(avg(log(Column_name)))

this has worked great, however I need to change this to the harmonic mean. Anyone have any ideas on the simplest way to do this.
A simple example of the harmonic mean:
If you want the harmonic mean of 10 and 20, you first
take 1/10 and 1/20, find their average, which is 3/40, and then take
the reciprocal of that, 40/3.

In algebra, the harmonic mean h of two numbers a and b is

1 / ( (1/a + 1/b) / 2),

or in other words

1/m = 1/2 (1/a + 1/b).

Thanks for any help!

I am also awarding the poitns from this question. (100 pts total)
https://www.experts-exchange.com/questions/20694999/Geometric-Mean-Function.html
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mohamadalikley
mohamadalikley

I First build at atble with the following discription
CREATE TABLE [test] (
      [a] [float] NOT NULL
) ON [PRIMARY]
GO

then ask it the following question :
declare @c float ;
declare @d int ;

Select @c = sum(1/a) From test ;
Select @d = count(*) FROM test ;
print @d *(1/@c)

and it work quit good .

hope it will be usefull for you.

Avatar of gigglick

ASKER

Hi guys,
Thank you both for your posts.  I am sure both should work, however, I have already found working solution (very similar to yours graye) with some help.  
Here is the xript in case any searchers com across this question: 1.0/(sum(1/column_name)/count(column))

Hope you guys are ok with me splitting the points between the both of you.

Thanks again!
You"ll need to go to :
https://www.experts-exchange.com/questions/20694999/Geometric-Mean-Function.html 
and post something for me to split the remaining points.
Thanks again!