Averaging yearly data


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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
Can you post sample data?
Some rows with actual data and the expected result.
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])

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
É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
Éric MoreauSenior .Net ConsultantCommented:
a minute too late!
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
And it should be Avg, not Sum
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.