Q&A for professional and enthusiast programmers
declare @postViews int declare @bountyPostViews int select @bountyPostViews = avg(p.viewcount) from posts p inner join votes v on p.Id = v.PostId where posttypeid = 1 and v.votetypeid = 8 and p.creationdate >= dateadd(month,datediff(month,0,getdate()) - 1,0) and p.creationdate <= dateadd(day,-1,dateadd(month,datediff(month,-2,getdate()),0)) select @postViews = avg(p.viewcount) from posts p where posttypeid = 1 and p.creationdate >= dateadd(month,datediff(month,0,getdate()) - 1,0) and p.creationdate <= dateadd(day,-1,dateadd(month,datediff(month,-2,getdate()),0)) select @postViews as AvgPostViewsSept2014, @bountyPostViews as AvgBountyViewsSept2014