declare @upvotes int declare @downvotes int declare @ed...

1

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 @upvotes   int
declare @downvotes int
declare @edits     int

select @upvotes   = UpVotes   from Users where Id = ##UserId##
select @downvotes = DownVotes from Users where Id = ##UserId##

select @edits = Count(*) from SuggestedEditVotes where TargetUserId = ##UserId## and VoteTypeId = 2

SELECT 
CASE

  WHEN VoteTypeId =  1 THEN 'Accepted Answer'
  WHEN VoteTypeId =  2 THEN 'Upvotes'
  WHEN VoteTypeId =  3 THEN 'Downvotes'
  WHEN VoteTypeId =  4 THEN 'Offensive Flags'
  WHEN VoteTypeId =  5 THEN 'Favorites'
  WHEN VoteTypeId =  6 THEN 'Close Votes cast before 2013-06-25'
  WHEN VoteTypeId =  7 THEN 'Reopen Votes'
  WHEN VoteTypeId =  8 THEN 'Bounties Started'
  WHEN VoteTypeId = 10 THEN 'Delete Votes'
  WHEN VoteTypeId = 11 THEN 'Undelete Votes'
  WHEN VoteTypeId = 12 THEN 'Spam Flags'
  WHEN VoteTypeId = 15 THEN 'Moderator Handling Flag'
  WHEN VoteTypeId = 16 THEN 'Approved Suggested Edit Review'
  
END AS [Vote Type],
COUNT(VoteTypeId) AS [Total Vote Count],
100 * (1.0 * CASE

  WHEN VoteTypeId =  2 THEN @upvotes
  WHEN VoteTypeId =  3 THEN @downvotes
  WHEN VoteTypeId =  5 THEN (select Count(*) from Votes where UserId = ##UserId## and VoteTypeId = 5)
  WHEN VoteTypeId =  8 THEN (select Count(*) from Votes where UserId = ##UserId## and VoteTypeId = 8)
  WHEN VoteTypeId = 16 THEN @edits
  
  ELSE null
END) / COUNT(VoteTypeId) AS [Your Percentage]

FROM Votes
WHERE VoteTypeId <> 9

GROUP BY VoteTypeId
ORDER BY [Total Vote Count] DESC

Enter Parameters

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