Number of votes per month

0

Please login or register to vote for this query.

(click on this box to dismiss)

Accounting only for votes cast on questions less than 31 days after the question was created.

Poker Meta

Q&A about the site for serious players and enthusiasts of poker

WITH UpVotesByMonth  AS (
    SELECT DATEADD (day, DATEDIFF (day, 0, v.CreationDate), 0)  AS [Day],
    COUNT (v.Id) AS Votes

    FROM Votes v 
    JOIN Posts p ON (p.Id = v.PostId) AND p.PostTypeId = 1
    WHERE v.VoteTypeId=2 and DATEDIFF(day, p.CreationDate, v.CreationDate) > 0

    GROUP BY DATEADD (day, DATEDIFF (day, 0, v.CreationDate), 0)
),
DownVotesByMonth  AS (
    SELECT DATEADD (day, DATEDIFF (day, 0, v.CreationDate), 0)  AS [Day],
    COUNT (v.Id) AS Votes

    FROM Votes v 
    JOIN Posts p ON (p.Id = v.PostId) AND p.PostTypeId = 1
    WHERE v.VoteTypeId=3 and DATEDIFF(day, p.CreationDate, v.CreationDate) > 0

    GROUP BY DATEADD (day, DATEDIFF (day, 0, v.CreationDate), 0)
)

SELECT
    v.[Day], 
    v.Votes+dv.Votes AS 'total',
    v.Votes AS 'upvotes',
    dv.Votes AS 'downvotes'

FROM UpVotesByMonth v
JOIN DownVotesByMonth dv ON v.[Day] = dv.[Day]
ORDER BY v.[Day]

Enter Parameters

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