Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles
SELECT Id AS [Post Link], (SELECT MAX(v) FROM (VALUES (ClosedDate), (LastEditDate)) AS value(v)) AS MaxDate FROM Posts WHERE CONVERT(date,ClosedDate) <= DATEADD(d, -5, CONVERT(date,GETUTCDATE())) AND (CONVERT(date,LastEditDate) <= DATEADD(d, -5, CONVERT(date,GETUTCDATE())) OR LastEditDate IS NULL) AND CreationDate >= DATEADD(d, -30, CONVERT(date,GETUTCDATE())) AND Score <= 1 AND AcceptedAnswerId IS NULL -- Exclude positive answers AND NOT EXISTS (SELECT * FROM Posts p2 WHERE p2.ParentId = Posts.Id AND Score > 0) -- Exclude closed as duplicate AND NOT EXISTS (SELECT * FROM PostLinks WHERE PostId = Posts.Id AND LinkTypeId = 3) -- Exclude migrated and merged AND NOT EXISTS (SELECT * FROM PostHistory WHERE PostId = Posts.Id AND PostHistoryTypeId IN (17,18,35,37)) ORDER BY 2