Tech Support Guy banner
Status
Not open for further replies.
1 - 3 of 3 Posts

·
Registered
Joined
·
7 Posts
Discussion Starter · #1 ·
Hi all~ thx if you can help

i have a database like follow name it A

A
======
Mark Weight
70 15
78 30
56 15
34 40

is there a sql statement that gives me the weighted average meaning 70*.15+78*.3+....34*.4 = ? wihout altering the database?

either sql command or mathemical trick is helpful
Thxs
 

·
Registered
Joined
·
106 Posts
Yep, well

SELECT SUM(Mark * (Weight/100)) from TableName

will give you what you asked for.

Not sure if that is what you really want though. It will give you the total of all the M*(W/100) when what I suspect you want is the average of all these. If that is the case, then use

select (sum(m * (w/100)))/count(*) from t

Ian
 
1 - 3 of 3 Posts
Status
Not open for further replies.
Top