Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sum of Averages

Author  Topic 

joglez
Starting Member

2 Posts

Posted - 2010-11-16 : 08:39:51
Hi, I need to display the sum of the averages of different colums all in one colum (just one big addition) how would i go about in doing this?
example: Select Name, (AVG(waterbills)+ AVG(gasbills)+AVG(electricitybills)) As MoneySpent

X002548
Not Just a Number

15586 Posts

Posted - 2010-11-16 : 08:44:57
Not sure what you mean...maybe supply ssosme sample data and expected results???


Select [Name], AVG(waterbills)+ AVG(gasbills)+AVG(electricitybills) As MoneySpent
FROM TABLE
GROUP BY [Name]




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-11-16 : 10:29:48
[code]Select
[Name],
avg(waterbills+gasbills+electricitybills) as MoneySpent
from
MyTable
group by
[Name][/code]

CODO ERGO SUM
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-11-16 : 22:16:44
or maybe this is what you want ?

SELECT NAME, (waterbills + gasbills + electricitybills) / 3.0 as MoneySpent
FROM SOMETABLE



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -