Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

averaging multiple fields from a table

Status
Not open for further replies.

nicmar

Programmer
Mar 4, 2003
11
US
How do you average multiple fields in SQL? To average one field, this is the syntax: SELECT AVG(Field1) FROM Table1;
So how do you average multiple fields together? Ex. (this is incorrect) SELECT AVG(Field1, Field2, Field3) FROM Table1; What is the syntax??? Any comments or suggestions are greatly appreciated.

Thank You,
nicmar
 
SELECT Count([WorkOrders].Total) AS CountOfTotal, Sum([WorkOrders].[TimeAllocated]) AS [SumOfTimeAllocated], Sum([WorkOrders].Total) AS SumOfTotal, ([SumofTimeAllocated]+[SumOfTotal])/[CountofTotal] AS FirstAverage, Avg([Total]+[TimeAllocated]) AS SecondAverage
FROM [WorkOrders];

I did it two ways in a query. The first way is to Sum the values and then add them together and divide by the Count of one of the fields. The other added them together and took the Average. The returned values were slightly different (about .0158 difference between the two methods).

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top