Comments from Questions and Answers per month posted with the tagname used and a given duration

1

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 count(*) AS TOTAL,
       DATENAME(mm, c.CreationDate) AS MONTH_NAME,
       DATENAME(yyyy, c.CreationDate) AS YEAR,
       MONTH(c.CreationDate) AS MONTH_NUM
 from  Comments c,
(
select  p1.id
  from  Posts p1, PostTags ptags1, Tags t1, PostTypes ptypes1 
 where  p1.posttypeid = ptypes1.id
   and  ptypes1.id = 1
   and  p1.id = ptags1.postid 
   and  ptags1.tagid = t1.id 
   and  t1.tagname = '##TagName##'
union
select  p2.id
  from  Posts p2, PostTypes ptypes2 
 where  p2.posttypeid = ptypes2.id
   and  ptypes2.id = 2
   and  p2.parentid in
     (  select  p3.id
          from  Posts p3, PostTags ptags3, Tags t3, PostTypes ptypes3 
         where  p3.posttypeid = ptypes3.id
           and  ptypes3.id = 1
           and  p3.id = ptags3.postid 
           and  ptags3.tagid = t3.id 
           and  t3.tagname = '##TagName##'
     )
) temp_p
where  temp_p.id = c.postid
and    c.CreationDate >= '##startdate##'
and    c.CreationDate <= '##enddate##'
group by DATENAME(yyyy, c.CreationDate), MONTH(c.CreationDate), DATENAME(mm, c.CreationDate)
order by DATENAME(yyyy, c.CreationDate) ASC, MONTH(c.CreationDate) ASC, DATENAME(mm, c.CreationDate) ASC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results