Q&A for professional and enthusiast programmers
Select CAST(year(p.CreationDate) as char(4))+'-'+CAST(DATEPART(wk,p.CreationDate) as char(2)) as week ,count(1) as Cnt ,avg(score) as Avg ,avg(VoteCount) as AvgVoteCount from Posts p JOIN (Select postid,count(1) as VoteCount from Votes group by postid) v on v.postid=p.id where p.CreationDate>dateadd(yy,-1,getdate()) group by year(p.CreationDate) ,DATEPART(wk,p.CreationDate) order by year(p.CreationDate),DATEPART(wk,p.CreationDate)