Score of accepted answer vs. score of highest non-accepted answer by creation year

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

-- For every question that is not closed, has score > 2, at least two answers
-- and one accepted answer for all years 2011-2020 display score of accepted
-- answer and score of highest scoring non-accepted answer
-- we simply get the scores of all answers and an additional boolean if an answer
-- is accepted, then we export the results and do further processing in a script
-- language of our choice

SELECT q.Id AS [QId], CASE WHEN q.AcceptedAnswerId = a.Id THEN 1 ELSE 0 END AS [AcceptedAnswer], q.Score AS [QScore], a.Score AS [AScore]
FROM Posts q
INNER JOIN Posts a
ON q.Id = a.ParentId
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##
and a.PostTypeId = 2
ORDER BY q.Id

Enter Parameters

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