Top Close Voters

1

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace

Q&A for members of the workforce navigating the professional setting

-- Returns all close voters since StartDate, ordered from most to least votes
-- Only counts closed votes that actually resulted in a closure,
-- and does not count deleted questions

-- I wouldn't recommend running this on StackOverflow due to its size

-- Variables - Set start date to timeframe you want
declare @startDate datetime
set @startDate = '1/1/2012'

declare @userid int
declare @users table
(
  userid int,
  closedcount int
)

-- Cursor for all users who can vote to close
declare cur cursor for 
    select id 
    from users
    -- 500 is required for close on beta sites so reduced
    where reputation >= ##RepForClose##
      and lastaccessdate >= @startDate
-- RepForClose: Rep needed to close on this site (500 for beta, 3000 for graduated)

open cur
fetch next from cur into @userid
while @@fetch_status = 0
begin

  insert into @users(userid, closedcount)
  SELECT @userid, count(*)
  FROM PostHistory 
  WHERE PostHistoryTypeId = 10 
  AND Text LIKE '%"Id":' + CAST(@userid AS nvarchar) + ',%'
  and creationdate >= @startDate
  
  fetch next from cur into @userid
end

close cur
deallocate cur


-- Return results
select top 100 u.ClosedCount, users.displayname as 'User'
from @users as u
left outer join users on u.userid = users.id
order by u.closedcount desc

Enter Parameters

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