Number of upvotes depending on age of the post (in weeks)

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

;with votes_cte as (
SELECT DATEDIFF(week, p.CreationDate, v.CreationDate) AS Weeks, v.Id as vid
FROM Votes v JOIN Posts p ON v.PostId=p.Id
WHERE VoteTypeId=2
)

SELECT Weeks, COUNT(*) FROM votes_cte
GROUP BY Weeks
ORDER BY Weeks

--VoteTypeId:
--1 = AcceptedByOriginator
--2 = UpMod (AKA upvote)
--3 = DownMod (AKA downvote)

--DATEDIFF returns the number of times the given period changed (for 23:59:00 and 00:01:00 the next day it returns 1 days, for 2018-12-31 and 2019-01-01 it returns 1 months/years)

Enter Parameters

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