posts with many comments

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

declare @endDate date;
select @endDate = max(creationdate) from comments;
declare @daysPerBin int= ##daysPerBin?7##;

select d,sum(cast(iif(numComments >= 5, 1, 0) as float)) / count(postId) as fracManyComments
from
(select dateadd(day,
@daysPerBin * (datediff(day, @endDate, max(p.creationdate))/@daysPerBin),
  @endDate) as d,count(c.id) as numComments,p.id as postId
from posts p
join comments c
on p.id = c.postid
group by p.id) as x
group by d
order by d asc

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results