Find users with the best accept rates, ordered by accept rate and total number of answers. Those with less than 5 answers are excluded.
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