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

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

-- 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##;


select 
  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 = t.id
where t.tagname = @tag) l
inner join posts r
on l.postid = r.id
group by year(creationdate), month(creationdate)
order by year, month

Enter Parameters

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