Averaging yearly data

Hi,

I have a table that contains monthly averages as follows:

Date(Datetime) fat_percent(Float), oil_percent(Float), MSG_Percent(Float), Quantity(INT).

For each year there are 12 entries. I would like to be able to calculate an average for each year.
The table hold 15 years of data, so I would like to return a row for each year with the with the values for each column.

Any help would be appreciated.

Thanks
Morpheus7Asked:
Who is Participating?
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
select Year([Date]) as TheYear, Avg(fat_percent) as AvgFat, AVG(oil_percent) as AvgOil, AVG(MSG_Percent) as AvgMSG, AVG(Quantity+0.0) as AvgQuantity
From myTable
group by Year([Date])
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Can you post sample data?
Some rows with actual data and the expected result.
0
 
Éric MoreauSenior .Net ConsultantCommented:
something like this?

select YEAR(Date), SUM(fat_percent), SUM(oil_percent), sum(MSG_Percent), sum(Quantity)
from your tablename
group by YEAR(Date)
Order by 1
0
 
Éric MoreauSenior .Net ConsultantCommented:
a minute too late!
0
 
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
And it should be Avg, not Sum
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.