Meta participation statistics for election-voters

0

Please login or register to vote for this query.

(click on this box to dismiss)

Mathematics

Q&A for people studying math at any level and professionals in related fields

-- Grab list of voters
DECLARE @election_start_date datetime = ##ElectionStartDate:string##
DECLARE @next_election_start_date datetime = ##NextElectionStartDate:string##

SELECT 
  u.AccountId AS [AccountId]
INTO
  #voters
FROM
  Users AS u
  INNER JOIN Badges AS b
    ON u.Id = b.UserId
WHERE
  b.Name = 'Constituent'
  AND DATEDIFF(MINUTE, @election_start_date, b.Date) > 0
  AND DATEDIFF(MINUTE, DATEADD(DAY, -1, @next_election_start_date), b.Date) < 0

-- Generate name of meta database
DECLARE @metadbname nvarchar(max) = DB_NAME() + '.Meta'

DECLARE @query nvarchar(max) = '
  USE [' + @metadbname + ']
  
  SELECT
    u.AccountId,
    u.Reputation,
    u.UpVotes + u.DownVotes AS [Votes],
    (SELECT COUNT(p.Id) FROM Posts AS p WHERE p.OwnerUserId = u.Id) AS [Posts],
    (SELECT COUNT(c.Id) FROM Comments AS c WHERE c.UserId = u.Id) AS [Comments]
  FROM
    Users AS u
  WHERE
    u.AccountId IN (SELECT AccountId FROM #voters)
  '

EXEC sp_executesql @query

Enter Parameters

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