Cross-Tag Tag Usage Breakdown

7

Please login or register to vote for this query.

(click on this box to dismiss)

A breakdown and usage count of each and every tag used alongside the given tag on posts. This is the full length version of the list that can be seen on the lower right-hand side of each tag's main search page, labeled "Related Tags": <https://stackoverflow.com/questions/tagged/javascript#h-related-tags> Also includes, for each tag in the list, a link to site search for the given and listed tag, and a link to *this query* using that tag.

History of Science and Math

Q&A for people interested in the history and origins of science and mathematics

DECLARE @TagId int = (  -- Get TagId of [tag] for use in SELECT
  SELECT
    t.Id
  FROM Tags t
  WHERE t.TagName = ##TagName:string##
)
                                            -- Then SELECT all tags from posts 
SELECT                                      -- tagged with [tag], and
  COUNT(otherTags.TagId) AS [Usage Count],  -- GROUP BY each unique tag
  t.TagName,                                -- to get the usage sums
  CONCAT(
    'site://questions/tagged/',
    ##TagName:string##,
    '+',
    t.TagName,
    '|Search for [',
    ##TagName:string##,
    '] [',
    t.TagName,
    ']'
  ) AS [Site Search Link],
  CONCAT(
    'https://data.stackexchange.com/stackoverflow/query/1398286/cross-tag-tag-usage-breakdown?TagName=',
    t.TagName,
    '#resultSets|[', 
    t.TagName, 
    '] Breakdown'
  ) AS [Cross-Tag Usage Query Link]
FROM PostTags ptg
JOIN PostTags otherTags ON otherTags.PostId = ptg.PostId
JOIN Tags t ON t.Id = otherTags.TagId
WHERE ptg.TagId = @TagId AND otherTags.TagId <> @TagId
GROUP BY otherTags.TagId, t.TagName 
UNION ALL
SELECT                                 
  COUNT(TagId) AS [Usage Count],      -- Finally, SELECT count of all posts using
  '(Total Questions)' AS [TagName],   -- [tag], just for comparison purposes, and
  '-' AS [Site Search Link],          -- UNION to the other SELECT
  '-' AS [Cross-Tag Usage Query Link] 
FROM PostTags
WHERE TagId = @TagId
ORDER BY COUNT(otherTags.TagId) DESC

-- TagName: Exact Name of Tag:

Enter Parameters

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