SQLTeam.com | Weblogs | Forums

Coverting Daily Data into a Monthly Average

tsql

#1

I have a Daily Production table and I want to Average it by the month. If I have production from 1/1/2018 thru 11/30/2018 on a daily basis. Give me the average production for January 2018, February 2018, March 2018 and so on. Please help I have tried everything.


#2
SELECT
	[Year] =  DATEPART(YEAR, ProductionDate),
	[Month] = DATEPART(MONTH,ProductionDate),
	AverageMonthlyProduction = AVG(DailyProduction * 1.0)
FROM
	YourTable
GROUP BY
	DATEPART(YEAR, ProductionDate),
	DATEPART(MONTH,ProductionDate)