sibling tag counts for a given tag in the past 365 days

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 @tagname NVARCHAR(MAX) = ##tagname:string##
DECLARE @tagid INT = (SELECT T.Id FROM Tags T WHERE T.TagName = @tagname)

SELECT
  MAX(T.TagName) AS Name,
  COUNT(PT.TagId) AS Count
FROM Posts Q
JOIN PostTags PT ON PT.PostId = Q.Id
JOIN Tags T ON T.Id = PT.TagId
WHERE
  Q.PostTypeId = 1
  AND Q.CreationDate > DATEADD(year, -1, getdate())
  AND Q.Tags like '%<'+@tagname+'>%'
  AND PT.TagId <> @tagid
GROUP BY PT.TagId
--HAVING COUNT(PT.TagId) > 5
ORDER BY COUNT(PT.TagId) DESC
;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results