Score of highest voted non-accepted answer

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

-- if there are two equally high scored, non-accepted answers we take the one that is older
SELECT sel.QId, sel.AScore, Min(Year(a.CreationDate)) AS [AYear]
FROM (SELECT top 50000 q.Id AS [QId], Max(a.Score) AS [AScore]
FROM Posts q
INNER JOIN Posts a
ON q.Id = a.ParentId and q.AcceptedAnswerId != a.Id
WHERE q.ClosedDate is null and q.PostTypeId = 1 and q.Score > 2
and q.AcceptedAnswerId is not null and q.AnswerCount > 1 and Year(q.CreationDate) = ##Y?2011##
GROUP BY q.Id
ORDER BY q.Id) sel
INNER JOIN Posts a
ON sel.QId = a.ParentId and sel.AScore = a.Score
GROUP BY sel.QId, sel.AScore
ORDER BY sel.QId

Enter Parameters

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