Post where a given tag was added and removed

1

Please login or register to vote for this query.

(click on this box to dismiss)

Monero Meta

Q&A about the site for developers and users of the secure, private and untraceable cryptocurrency Monero

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

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

Enter Parameters

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