Q&A for professional and enthusiast programmers
-- Most popular tags in a year DECLARE @Year INT = ##Year## select num.TagName as Tag, row_number() over (order by rate.Rate desc) as YearRank, row_number() over (order by num.Num desc) as AllTimeRank, rate.Rate as QuestionsYear, num.Num as QuestionsTotal from (select count(PostId) as Rate, TagName from Tags, PostTags, Posts where Tags.Id = PostTags.TagId and Posts.Id = PostId and Posts.CreationDate < CAST(@Year + 1 AS NVARCHAR) + '-01-01' and Posts.CreationDate >= CAST(@Year AS NVARCHAR) + '-01-01' group by TagName) as rate INNER JOIN (select count(PostId) as Num, TagName from Tags, PostTags, Posts where Tags.Id = PostTags.TagId and Posts.Id = PostId group by TagName having count(PostId) > 800) as num ON rate.TagName = num.TagName order by rate.rate desc ;