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

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

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.

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

select YEAR(Date), SUM(fat_percent), SUM(oil_percent), sum(MSG_Percent), sum(Quantity)

from your tablename

group by YEAR(Date)

Order by 1

a minute too late!

And it should be Avg, not Sum

Some rows with actual data and the expected result.