Percentage of Accepted Answers

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

DECLARE @UserId int = ##UserId##
DECLARE @AnswerPostTypeId int = 2

SELECT 
     (ROUND(
            CAST(Count(answer.Id) AS float) / (SELECT Count(*) 
            FROM Posts 
            WHERE OwnerUserId = @UserId AND PostTypeId = @AnswerPostTypeId
           ) * 100
         , 2
         )
     )  
    AS Accepted_Answers_Percentage
FROM
    Posts question
  INNER JOIN
    Posts answer ON question.AcceptedAnswerId = answer.Id
WHERE
    answer.OwnerUserId = @UserId
  AND
    answer.PostTypeId = @AnswerPostTypeId

Enter Parameters

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