Top 10 Total All-Time UpVoted Users

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

create table #Reps(UserId int, Reputation int)

insert into #Reps (UserId, Reputation) 
select Id, Reputation from Users
order by Reputation desc

create table #TotalVotes(UserId int, Upvotes int, Downvotes int, Reputation int)

insert into #TotalVotes (UserId, Reputation) 
select top 10 * from #Reps
order by Reputation desc

update #TotalVotes
set Upvotes = (
SELECT Count(*)
  From Votes AS v
  INNER JOIN Posts AS p ON v.PostId = p.Id
  where p.OwnerUserId = #TotalVotes.UserId
    AND v.VoteTypeId = 2
    ),
    
Downvotes = (
SELECT Count(*)
  From Votes AS v
  INNER JOIN Posts AS p ON v.PostId = p.Id
  where p.OwnerUserId = #TotalVotes.UserId
    AND v.VoteTypeId = 3
    )
    
select UserId as [User Link], Upvotes, Downvotes, Reputation from #TotalVotes
order by Upvotes desc

Enter Parameters

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