What's going up, what's going down


Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

  y int,
  numPosts int

INSERT INTO @AnnualPosts (y, numPosts)

  select year(CreationDate), count(id)
  from Posts
  where answerCount + CommentCount > 0
  group by year(CreationDate)

  tagId int,
  tagName varChar(32),
  usage_15 int, 
  usage_16 int

INSERT INTO @TopTags (tagID, tagName, usage_15, usage_16)

  select top 1000 t.id tagId, t.tagName,  
  sum (case when year(p.creationDate) = 2015 then 1 else 0 end) TagUsage2015, 
  sum (case when year(p.creationDate) = 2016 then 1 else 0 end) TagUsage2016 
  from tags t
  join PostTags pTags on pTags.tagId = t.id
  join Posts p on pTags.postId = p.id
  where year(p.creationDate) in (2015, 2016)
  group by t.Id, t.tagName
  order by count(p.id) desc 
select topTags.*, 
  annualPosts15.numPosts as TotalPosts2015, 
  annualPosts16.numPosts as TotalPosts2016
from @TopTags topTags
join @AnnualPosts annualPosts15 on annualPosts15.y  = 2015
join @AnnualPosts annualPosts16 on annualPosts16.y  = 2016

Enter Parameters

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