Best accept rate percentage

0

Please login or register to vote for this query.

(click on this box to dismiss)

Find users with the best accept rates, ordered by accept rate and total number of answers. Those with less than 5 answers are excluded.

Stack Overflow

Q&A for professional and enthusiast programmers

-- Best accept rate percentage
-- Find users with the best accept rates, ordered by accept rate and total number of answers. Those with less than 5 answers are excluded.

DECLARE @MinRate float = ##MinRate:float##

SELECT 
    t.OwnerUserId AS [User Link],
    t.Total,
    Round(t.Accepted * 100.0 / t.Total, 1) AS [Percent]
  FROM
    (SELECT
         a.OwnerUserId,
         Count(a.Id) AS [Total],
         Sum(CASE q.AcceptedAnswerId WHEN a.Id THEN 1 ELSE 0 END) AS [Accepted]
       FROM Posts AS a
         JOIN Posts AS q
           ON a.ParentId = q.Id
       WHERE q.postTypeId = 1 AND a.postTypeId = 2 AND a.OwnerUserId <> q.OwnerUserId
       GROUP BY a.OwnerUserId
   ) AS t 
WHERE t.[Total] >= 6 AND (CAST(t.[Accepted] AS FLOAT) / t.[Total]) >= @MinRate
ORDER BY (CAST(t.[Accepted] AS FLOAT) / t.[Total]) DESC, t.[Total] DESC

Enter Parameters

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