Total Questions Tagged with Both [Tag1] and [Tag2]

2

Please login or register to vote for this query.

(click on this box to dismiss)

Gets the quantity of questions tagged with [Tag1] and [Tag2] individually and the total quantity of questions tagged with both together.

Constructed Languages Meta

Q&A about the site for designers and users of artificial or invented languages, consciously developed instead of having developed naturally

DECLARE @TagId int = (
SELECT
  t.Id
FROM Tags t
WHERE t.TagName = ##TagName:string##
)

DECLARE @OtherTagId int = (
SELECT
  t.Id
FROM Tags t
WHERE t.TagName = ##OtherTagName:string##
)

SELECT
  CONCAT('Questions tagged [', ##TagName:string##, '] && [', ##OtherTagName:string## ,']'),
  COUNT(otherTags.TagId) AS [Usage Count]
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 = @OtherTagId
GROUP BY otherTags.TagId, t.TagName 
UNION ALL
SELECT
  CONCAT('Questions tagged [', ##TagName:string##, ']'),
  COUNT(TagId) AS [Usage Count]
FROM PostTags
WHERE TagId = @TagId
UNION ALL
SELECT
  CONCAT('Questions tagged [', ##OtherTagName:string##, ']'),
  COUNT(TagId) AS [Usage Count]
FROM PostTags
WHERE TagId = @OtherTagId
ORDER BY COUNT(otherTags.TagId) DESC

-- TagName: Exact Name of Tag#1:
-- OtherTagName: Exact Name of Tag#2:

Enter Parameters

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