Number of upvotes/downvotes per week between two dates

0

Please login or register to vote for this query.

(click on this box to dismiss)

MathOverflow

Q&A for professional mathematicians

SELECT 
---https://stackoverflow.com/questions/1267126/get-the-week-start-date-and-week-end-date-from-week-number
  DATEADD(dd, -(DATEPART(dw, CreationDate)-1), CAST(CreationDate AS Date)) [WeekStart],
SUM(case when v.VoteTypeId IN (2,3) then 1 else 0 end) AS [Up+DownVotes],
  SUM(case when v.VoteTypeId = 2 then 1 else 0 end) AS [UpVotes],
  SUM(case when v.VoteTypeId = 3 then 1 else 0 end) AS [DownVotes],
  SUM(case when v.VoteTypeId = 1 then 1 else 0 end) AS [Accepts]
FROM Votes v
WHERE (CreationDate >= '##Date1?2021-01-01##') AND (CreationDate <= '##Date2?2023-01-01##')
GROUP BY DATEADD(dd, -(DATEPART(dw, CreationDate)-1), CAST(CreationDate AS Date))
ORDER BY DATEADD(dd, -(DATEPART(dw, CreationDate)-1), CAST(CreationDate AS Date))

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results