Q&A for people interested in the history and origins of science and mathematics
DECLARE @start datetime = DATEADD(day, -7*52*1, GETDATE()); DECLARE @stop datetime = DATEADD(day, -2, GETDATE()); SELECT DATEADD(week, datediff(week, @start, CreationDate), @start) as [Week], COUNT(CASE WHEN VoteTypeId = 2 THEN 1 END) AS [Upvotes], COUNT(CASE WHEN VoteTypeId = 3 THEN 1 END) AS [Downvotes] FROM Votes WHERE CreationDate >= @start and CreationDate < @stop GROUP BY dateadd(week, datediff(week, @start, CreationDate), @start) ORDER BY dateadd(week, datediff(week, @start, CreationDate), @start)