Shows the trend for your favourite tag
Q&A for linguists, teachers, and students wanting to discuss the finer points of the Latin language
DECLARE @TagName varchar(255) = '##TagName##'; DECLARE @PostCountByMonth TABLE ( [date] datetime, [##TagName##Count] int, UNIQUE CLUSTERED ([date]) ); INSERT INTO @PostCountByMonth SELECT dateadd(month, DATEDIFF(month, '', p.CreationDate), '') [date], count(*) [##TagName##Count] FROM ( SELECT p.CreationDate FROM Posts p INNER JOIN PostTags pt on pt.PostId = p.Id INNER JOIN Tags t on pt.TagId = t.Id WHERE t.TagName = @TagName and p.PostTypeId = 1 -- Question ) p GROUP BY DATEDIFF(month, '', p.CreationDate) ORDER BY DATEDIFF(month, '', p.CreationDate); SELECT p1.[date], sum(p2.[##TagName##Count]) [count] FROM @PostCountByMonth p1 INNER JOIN @PostCountByMonth p2 ON p1.[date] >= p2.[date] GROUP BY p1.[date]