Q&A about the site for students and teachers of all martial arts
DECLARE @tagName NVARCHAR(255) = 'angular' -- TagName: Tag name of the question. DECLARE @beginDate DATETIME = '2016-01-01' DECLARE @endDate DATETIME = '2020-12-31' SELECT T.Month, sum(ViewCount) as ViewCount, sum(AnswerCount) as AnswerCount, sum(CommentCount) as CommentCount, sum(FavoriteCount) as FavoriteCount, sum(Score) as Score FROM (SELECT CAST( CAST(DATEPART(YEAR, CreationDate) AS NVARCHAR) + '-' + CAST(DATEPART(MONTH, CreationDate) AS NVARCHAR) + '-01' AS DATETIME) AS 'Month', p.ViewCount, p.AnswerCount, p.CommentCount, p.FavoriteCount, p.Score FROM Posts p INNER JOIN PostTags pt ON p.Id = pt.PostId INNER JOIN Tags t ON t.Id = pt.TagId WHERE (p.PostTypeId = 1) AND (t.TagName = @tagName) AND (p.CreationDate BETWEEN @beginDate AND @endDate) GROUP BY DATEPART(YEAR, CreationDate), DATEPART(MONTH, CreationDate), p.ViewCount, p.AnswerCount, p.CommentCount, p.FavoriteCount, p.Score) T GROUP BY T.Month ORDER BY T.Month ASC