Users with lowest defeat rate of their answers

0

Please login or register to vote for this query.

(click on this box to dismiss)

Robotics Meta

Q&A about the site for professional robotic engineers, hobbyists, researchers and students

DECLARE @MinAcceptedAnswers int = ##MinAcceptedAnswers##

SELECT TOP 200
  count(*) AS NumAnswers,
  sum(case when q.AcceptedAnswerId <> a.Id then 1 else 0 end) AS NumDefeated,
  CAST(sum(case when q.AcceptedAnswerId <> a.Id then 1 else 0 end)*1.0/count(*) AS DECIMAL(3,2)) AS fraction,
  u.Id AS UserId,
  u.DisplayName AS Name
FROM Posts a
INNER JOIN Users u ON u.Id = a.OwnerUserId
INNER JOIN Posts q ON a.ParentId = q.Id
WHERE 
  (q.OwnerUserId <> u.Id OR q.OwnerUserId IS NULL)   --no self answers
  AND q.AcceptedAnswerId IS NOT NULL -- only count cases with another accepted answer
GROUP BY u.Id, u.DisplayName
HAVING sum(case when q.AcceptedAnswerId = a.Id then 1 else 0 end) >= @MinAcceptedAnswers
ORDER BY fraction ASC, NumAnswers DESC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results