Number of posts for a selected tag, broken down by month and year


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- get all postids with a certain tag
-- group those posts into buckets
-- remember to put single quotes in parameter, for whatever reason

declare @tag varchar(25) = ##tagname##;

  row_number() over(order by 
    year(creationdate), month(creationdate)) as monthid, 
  month(creationdate) as month, 
  year(creationdate) as year, count(*) as number
from (select p.postid
from posttags p
inner join tags t
on p.tagid =
where t.tagname = @tag) l
inner join posts r
on l.postid =
group by year(creationdate), month(creationdate)
order by year, month

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results