Q&A for professional and enthusiast programmers
WITH myEdits AS ( SELECT ph.PostId, MAX( ph.Id ) AS MyLatestEditId, MAX( ph.CreationDate ) AS MyLatestDT FROM PostHistory AS ph WHERE ph.UserId = 159145 AND ph.PostHistoryTypeId = 5 /* Edit Body */ GROUP BY ph.PostId ), otherPeoplesPosts AS ( SELECT p.Id AS PostId, p.LastEditDate, p.LastEditorUserId, CASE p.PostTypeId WHEN 1 THEN 'Q' WHEN 2 THEN 'A' ELSE 'O' END AS PostType FROM Posts AS p WHERE p.OwnerUserId <> 159145 ) SELECT p.PostId AS "Post Link", p.PostType, e.MyLatestDT, p.LastEditDate, DATEDIFF( day, p.LastEditDate, e.MyLatestDT ) AS DaysSince FROM otherPeoplesPosts AS p INNER JOIN myEdits AS e ON e.PostId = p.PostId WHERE p.LastEditorUserId <> 159145;