Q&A for ebook publishers and readers
-- Money for Jam -- set nocount on declare @latestDate datetime select @latestDate = max(CreationDate) from Posts declare @VoteStats table (PostId int, up int, down int, CreationDate datetime) insert @VoteStats select p.Id, up = sum(case when VoteTypeId = 2 then case when p.ParentId is null then 5 else 10 end else 0 end), down = sum(case when VoteTypeId = 3 then 2 else 0 end), p.CreationDate from Votes v join posts p on v.postid = p.id where v.VoteTypeId in (2,3) and p.CommunityOwnedDate is null and datediff(day, p.CreationDate, v.CreationDate) > 60 group by p.Id, p.CreationDate, p.ParentId set nocount off select top 2000 PostId as [Post Link], convert(decimal(10,2), up - down) /datediff(day, vs.CreationDate, @latestDate) as average, datediff(day, CreationDate, @latestDate) as Days, (up - down) as [Total Rep], up, down from @VoteStats vs order by average desc