Avatar of Morpheus7
Morpheus7
 asked on

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
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Phillip Burton

8/22/2022 - Mon
Vitor Montalvão

Can you post sample data?
Some rows with actual data and the expected result.
ASKER CERTIFIED SOLUTION
Phillip Burton

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Éric Moreau

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 Moreau

a minute too late!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Phillip Burton

And it should be Avg, not Sum