;with comments_month as ( select eomonth(creationdate) [m...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

;with comments_month as
(
select eomonth(creationdate) [mon]
, count(*) [# of comments]
from comments
group by eomonth(creationdate)
)
, posts_month as 
(select eomonth(creationdate) [mon]
, count(*) [# of posts]
, sum(case when posttypeid = 1 then 1 else 0 end) [# questions]
, sum(case when posttypeid = 2 then 1 else 0 end) [# answers]
from postswithdeleted
group by eomonth(creationdate)
)

select mon
     ,sum( [# of comments]) [# of comments]
     , sum( [# questions]) [# questions]
     , sum( [# answers]) [# answers]
     ,  sum( [# of posts]) [# of posts]
from 
(
select mon
     , [# of comments]
     , 0 [# questions]
     , 0 [# answers]
     , 0 [# of posts]
from comments_month
union 
select mon
     , 0 [# of comments]
     , [# questions]
     , [# answers]
     , [# of posts]
from posts_month
) data
group by mon
order by mon

Enter Parameters

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