Q&A about the site for enthusiasts and power users of the Android operating system
/* select *, count(*) as count from ( select CAST( cast(DATEPART(YYYY, CreationDate) as varchar) + '-' + cast(DATEPART(MM, CreationDate) as varchar) + '-01' as datetime) [Month], t.TagName from Posts p join PostTags pt on pt.PostId = p.Id join Tags t on t.Id = pt.TagId where TagId in ( select top 10 Id from Tags order by Count desc ) ) as X group by TagName, [Month] order by [Month] desc, TagName asc */ SELECT *, COUNT(*) AS Count FROM ( SELECT CAST( CAST(DATEPART(YYYY, CreationDate) AS varchar) + '-' + CAST(DATEPART(MM, CreationDate) AS varchar) + '-01' AS DATETIME) [Month], t.TagName FROM Posts p LEFT JOIN PostTags pt ON pt.PostId = p.Id JOIN Tags t ON t.Id = pt.TagId WHERE TagId IN ( SELECT TOP 5 Id FROM Tags ORDER BY Count DESC ) ) AS X WHERE [Month] >= CAST('2012-04-01' as datetime) AND [Month] < CAST('2012-07-01' as datetime) GROUP BY TagName, [Month] ORDER BY [Month] ASC, TagName ASC