Posts where a given tag was added and removed

1

Please login or register to vote for this query.

(click on this box to dismiss)

Gardening and Landscaping Meta

Q&A about the site for gardeners and landscapers

;  with firstwithtag_cte as
(
SELECT
DISTINCT p.Id AS pid, Min(ph1.Id) AS phWithId
FROM PostHistory ph1 INNER JOIN Posts p ON ph1.PostId=p.Id
WHERE ph1.PostHistoryTypeId in (3,6,9)
  and ph1.Text Like '%<##tagName##>%'
GROUP BY p.Id
), firstwithouttag_cte as
(SELECT
  pid, MIN(ph2.Id) as phWithoutId
FROM firstwithtag_cte INNER JOIN PostHistory ph2 ON ph2.PostId=pid
  WHERE (ph2.Id>phWithId)
   AND ph2.PostHistoryTypeId in (3,6,9)
   AND NOT(ph2.Text Like '%<##tagName##>%')
GROUP BY pid
)

SELECT pid AS [Post Link],
  url = 'site://posts/' + CAST(pid AS varchar)+'/revisions',
  CreationDate as dateWithout
FROM PostHistory INNER JOIN firstwithouttag_cte ON PostHistory.Id=phWithoutId
ORDER BY pid ASC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results