Select CAST(year(p.CreationDate) as char(4))+'-'+CAST(DAT...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

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)

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results