Reputation points per month (for answers only)

1

Please login or register to vote for this query.

(click on this box to dismiss)

Gets the reputation points gained by a user, per month, for his answers.

Stack Overflow

Q&A for programmers

DECLARE @UserId int = ##UserId##

SELECT 
    YEAR(Votes.CreationDate) AS Year, 
    MONTH(Votes.CreationDate) AS Month,
    (SELECT 
        COUNT(*) 
     FROM
         Posts P1 
     WHERE 
         P1.PostTypeId = 2 AND OwnerUserId = @UserId AND
         YEAR(P1.CreationDate) = YEAR(Votes.CreationDate) AND
         MONTH(P1.CreationDate) = MONTH(Votes.CreationDate)) AS Answers,
    SUM(CASE
        WHEN VoteTypeId = 1 THEN 15 -- Accepted answer.
        WHEN VoteTypeId = 2 AND PostTypeId = 2 THEN 10 -- Upvoted answer.
        WHEN VoteTypeId = 3 THEN -2 -- Downvote.
        WHEN VoteTypeId = 9 THEN BountyAmount -- Earned Bounty.
    END) AS Rep
FROM Votes
    INNER JOIN Posts ON Posts.Id = Votes.PostId
WHERE 
    Posts.OwnerUserId = @UserId
GROUP BY
    YEAR(Votes.CreationDate), MONTH(Votes.CreationDate)
ORDER BY
    Year DESC, Month DESC

Enter Parameters

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