/*--select datepart(week, CreationDate) from Posts where ...


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

/*--select datepart(week, CreationDate) from Posts where Id=13375558;
DATEPART(week, p.CreationDate) 'Week Number',
--DATEADD(dd, -(DATEPART(dw, p.CreationDate)-1), p.CreationDate) 'Week Start Date',
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',
SUM(CASE WHEN p.AcceptedAnswerId is NULL THEN 0 ELSE 1 END) as 'Total Accepted Answers',
SUM(CASE WHEN v.Id is null THEN 0 ELSE 1 END) as 'Total Votes'
--SUM(CASE WHEN DATEPART(week, u.LastAccessDate)=DATEPART(week,p.CreationDate)
 --   THEN 1
 --   ELSE 0 END) as ActiveUsers,
--SUM(CASE WHEN DATEPART(week, u.CreationDate)=DATEPART(week,p.CreationDate) 
  --  THEN 1
    --ELSE 0 END) as Active    
FROM Posts p
full OUTER JOIN Votes v on p.Id=v.PostId
--INNER JOIN Users u on u.Id = p.LastEditorUserId
GROUP by DATEPART(week, p.CreationDate), DATEPART(week, v.CreationDate)
--DATEPART(week, u.CreationDate), DATEPART(week, u.LastAccessDate)
ORDER by DATEPART(week, p.CreationDate) DESC

WITH WeekVotes AS(
  DATEPART(week, v.CreationDate) 'Week Number',
  COUNT(v.Id) as 'Total Votes'
  FROM Votes v
  GROUP BY DATEPART(week, v.CreationDate)
with WeekUsers as(
  DATEPART(week, u.CreationDate) 'Week Number',
  COUNT(u.Id) as 'Active Users'
  FROM Users u
  GROUP BY DATEPART(week, u.CreationDate)--, DATEPART(week, u.LastAccessDate)

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results