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

Averaging by year 1

Status
Not open for further replies.

gemoon

Programmer
Mar 22, 2002
55
US
This seems like an easy problem, but for the life of me I can’t get the solution. I’m trying to write a query that averages values by year. I think I’m on the right track by using the DatePart function, but I keep getting a compile error message. I have two tables with 2 & 3 fields respectively

tblA
A date

tblB
B A X

A and B are the primary keys (both are integers). date has format dd/mm/yy and x is a number

The query that I’ve created is as follows
SELECT DatePart('yyyy',[tblA].[date]) AS Expr1, Avg(tblB.X) AS AvgOfX
FROM tblA LEFT JOIN tblB ON tblA.A = tblB.A
GROUP BY DatePart('yyyy',[tblA].[date]);

Thanks in advance for the help,
Ed

 
Thank you very much. I tried your solution and was still getting the same compile error. This time it refered to 'year(tblA.[date])'. I think the problem is with my database. It has become corrupted or something similar I coppied these two tables and the query into a new database and the query worked fine. My query above also worked in the new database. Luckily I don't have too many tables to transfer over.

Thanks for the help,
Ed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top