Q&A about the site for administrators, end users, developers and designers for Craft CMS
SELECT TOP 30 p.Id As [Post Link], p.ClosedDate,p.CreationDate, v.CreationDate /* Count(v.VoteTypeId) As DeleteVotes, p.Score + Sum(a.Score) as Scores, CASE WHEN 3 + ((p.Score + Sum(a.Score)) /20)>10 THEN 10 ELSE 3 + ((p.Score + Sum(a.Score)) /20) END as VotesNeededToDelete, Count(v.VoteTypeId) as DeleteVotes, CASE WHEN 3 + ((p.Score + Sum(a.Score)) /20)>10 THEN 10 ELSE 3 + ((p.Score + Sum(a.Score)) /20) END - Count(v.VoteTypeId) AS VotesRemaining */ FROM Votes AS v INNER JOIN Posts AS p ON v.PostId=p.Id INNER JOIN Posts as a on a.ParentId = p.id WHERE v.VoteTypeId=10 AND p.ClosedDate IS NOT NULL AND v.CreationDate > p.ClosedDate AND p.PostTypeId=1 --GROUP BY p.Id, p.Score, p.ClosedDate, p.CreationDate --HAVING Count(v.VoteTypeId)>0 --ORDER BY DeleteVotes DESC ORDER BY p.Id