Posts where a given tag was added and removed

0

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, ph1.Id AS phWithId, ph1.CreationDate AS dateWith
FROM PostHistory ph1 INNER JOIN Posts p ON ph1.PostId=p.Id
WHERE ph1.PostHistoryTypeId in (3,6,9)
  and ph1.Text Like '%<##tagName##>%'
), firstwithouttag_cte as
(SELECT
  pid, dateWith, 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, dateWith
)

SELECT pid AS [Post Link],
  url = 'site://posts/' + CAST(pid AS varchar)+'/revisions',
  dateWith, 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