Number of posts per week - between two dates (including the deleted posts)

0

Please login or register to vote for this query.

(click on this box to dismiss)

Computer Science

Q&A for students, researchers and practitioners of computer science

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],
  COUNT(p.Id) AS [Total Posts],
  SUM(case when p.PostTypeId = 1 then 1 else 0 end) AS [Total Questions],
  SUM(case when p.PostTypeId = 2 then 1 else 0 end) AS [Total Answers]
FROM PostsWithDeleted p
WHERE (CAST(p.CreationDate AS Date)>= '##Date1?2021-01-01##') AND (CAST(p.CreationDate AS Date) <= '##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