Q&A for professional and enthusiast programmers
select DATEADD(week, DATEDIFF(week, -1, creationdate), -1) [week] , count(distinct owneruserid) [# unique users] , count(distinct case when posttypeid = 1 then owneruserid else null end) [# q-users] , count(distinct case when posttypeid = 2 then owneruserid else null end) [# a-users] , count(*) [total] from posts where creationdate between DATEADD(week, DATEDIFF(week, -1, '2018-01-01'), -1) and DATEADD(week, DATEDIFF(week, -1, getdate()), -1) group by DATEADD(week, DATEDIFF(week, -1, creationdate), -1) order by DATEADD(week, DATEDIFF(week, -1, creationdate), -1)