Number of questions per tag per 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

DECLARE @startDate DATE = '2008-08-01';
DECLARE @endDate DATE = '2017-07-01';

select Id as PostId,
  YEAR(Posts.CreationDate) as [Year],
  MONTH(Posts.CreationDate) as [Month]
    into #PostSet
    from Posts
    where PostTypeId = 1 and
    DeletionDate is null and
    CreationDate > @startDate and
    CreationDate < @endDate

select [Year], [Month], Count(*) as Total
  into #MonthTotals
  from #PostSet
  group by [Year], [Month]

select [Year], [Month], Tags.TagName as Tag, Count(*) as Number
  into #MonthTagNumber
  from #PostSet
  join PostTags on #PostSet.PostId = PostTags.PostId
  join (select * from Tags where Count >= 10000) Tags on PostTags.TagId = Tags.Id
  group by [Year], [Month], Tags.TagName

select #MonthTagNumber.[Month] as [Month],
       #MonthTagNumber.[Year] as [Year],
       Tag, Number, Total
  from #MonthTagNumber
  join #MonthTotals on #MonthTagNumber.[Month] = #MonthTotals.[Month] and
                       #MonthTagNumber.[Year] = #MonthTotals.[Year]
  order by #MonthTagNumber.[Year], #MonthTagNumber.[Month], Tag

Enter Parameters

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