Q&A about the site for members of the workforce navigating the professional setting
select A.PostId as PostId, D.DateId as Date, count(C1.Id) as CommentCount ----Assuming that there is a date_ddmmyyyy column on the date dimension table from (select top 50 C.PostId from Comments C where DATEDIFF(day,C.CreationDate , GETDATE()) <= 365 group by C.PostId order by count(C.Id) desc ) A ---Getting top 50 posts of the year join Comments C1 on A.PostId = C1.PostId ---Joining to get all comments on top 50 posts of the year. join ( select C2.CreationDate, CONVERT(date, C2.CreationDate) as DateId from Comments C2 ) D on C1.CreationDate = D.CreationDate ----Replicating the date dimension table group by A.PostId, D.DateId order by A.PostId, D.DateId ;