Average Accepted Answer Percentage of Users Like UserId Compared to UserId

1

Please login or register to vote for this query.

(click on this box to dismiss)

Displays average accepted answer percentage of users similar to userId (answer count between 80% and 120% of userId's answer count) compared to accepted answer percentage for userId

Stack Overflow

Q&A for professional and enthusiast programmers

-- Average Accepted Answer Percentage of Users Like UserId Compared to UserId
-- Displays average accepted answer percentage of users similar to userId
-- (answer count between 80% and 120% of userId's answer count)
-- compared to accepted answer percentage for userId

DECLARE @AnwerCount INT;
DECLARE @MinimunAnswers INT;
DECLARE @MaximumAnswers INT;

SELECT
    @AnwerCount = Count(a.Id)
FROM    Posts AS a
JOIN    Posts AS q
     ON a.ParentId = q.Id
WHERE
        q.PostTypeId = 1
    AND a.PostTypeId = 2
 AND a.OwnerUserId = ##UserId## 

SET @MinimunAnswers = @AnwerCount * .8
SET @MaximumAnswers = @AnwerCount * 1.2



SELECT
    'Everyone' AS [User],
    ROUND(AVG( AcceptedPercentage.Accepted ),2) AS [Accepted Answer Percentage]
FROM
 ( 
SELECT TOP 10000
    ROUND(SUM(CASE q.AcceptedAnswerId WHEN a.Id THEN 1 ELSE 0 END) * 100.0 / Count(a.Id), 1) AS [Accepted]
FROM    
    Posts AS a
    JOIN    Posts AS q
    ON a.ParentId = q.Id
WHERE
        q.PostTypeId = 1
    AND a.PostTypeId = 2
    AND q.AcceptedAnswerId IS NOT NULL
    
GROUP BY
    a.OwnerUserId
HAVING
    COUNT(a.Id) BETWEEN @MinimunAnswers
                AND     @MaximumAnswers
) AS AcceptedPercentage

UNION

SELECT
  'User ##UserId##' AS [User],
        Round(Sum(CASE q.AcceptedAnswerId WHEN a.Id THEN 1 ELSE 0 END) * 100.0 / Count(a.Id), 2) AS [Accepted Answer Percentage]
FROM    Posts AS a
JOIN    Posts AS q
     ON a.ParentId = q.Id
WHERE
        q.PostTypeId = 1
    AND q.AcceptedAnswerId IS NOT NULL
    AND a.PostTypeId = 2
 AND a.OwnerUserId = ##UserId## 
GROUP BY
        a.OwnerUserId

Enter Parameters

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