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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the average? 1

Status
Not open for further replies.

tlove161

Technical User
Feb 5, 2004
42
0
0
US
Hello-

I am trying to find the average of the groups in a query. This is the expression and it does not work:

TEST: Sum(([OpDurMin])/Count([ID]))

It tells me something about an aggregate function. How can I do this in one query? Thanks.
 
Since you didn't include the entire SQL statement, I'm going to assume you have something like:

SELECT Field1, Field2, Sum(([OpDurMin])/Count([ID])) As Test
FROM SomeTable

Anytime you use an aggregate function (like SUM, COUNT, AVG) you have to include a GROUP BY clause and all the non-aggregate fields have to be included. This would work with the example above:

SELECT Field1, Field2, Sum(([OpDurMin])/Count([ID])) As Test
FROM SomeTable
GROUP BY Field1, Field2

In the future, I would suggest that to get specific help you include the actual error message, and all the information necessary to assist you (like the whole SQL statement)






Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual
 
You may also consider the AVG aggregate function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Leslie-

Thank you for the help. Your suggestion worked. I am still new to queries and sql. This site is great for learning. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top