Gets the reputation points gained by a user, per month, for his answers.
Q&A for professional and enthusiast 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