Query 3 from http://meta.stackexchange.com/a/106/147650

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT COUNT(DISTINCT pQ.Id) AS Questions
  FROM dbo.Posts pQ
  INNER JOIN dbo.Posts pA1 ON pQ.AcceptedAnswerId = pA1.Id
  INNER JOIN dbo.Posts pA2 ON pA2.ParentId = pQ.Id AND pA1.CreationDate < pA2.CreationDate AND pA2.Score > pA1.Score
  WHERE pQ.PostTypeId = 1 
  AND pQ.ClosedDate IS NULL
  AND NOT EXISTS (SELECT Id FROM dbo.Posts pA WHERE pQ.Id = pA.ParentId AND pA1.CreationDate > pA.CreationDate)

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results