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.

Stack Overflow

Q&A for professional and enthusiast programmers

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

    FROM Votes v 
    JOIN Posts p ON (p.Id = v.PostId) AND p.PostTypeId = 1
    WHERE v.VoteTypeId=2
    GROUP BY DATEADD (month, DATEDIFF (month, 0, v.CreationDate), 0)
),
DownVotesByMonth  AS (
    SELECT DATEADD (month, DATEDIFF (month, 0, v.CreationDate), 0)  AS [Month],
    COUNT (v.Id) AS Votes

    FROM Votes v 
    JOIN Posts p ON (p.Id = v.PostId) AND p.PostTypeId = 1
    WHERE v.VoteTypeId=3
    GROUP BY DATEADD (month, DATEDIFF (month, 0, v.CreationDate), 0)
)

SELECT
    v.[Month], 
    CAST(v.Votes as float)/CAST((v.Votes+dv.Votes) as float) AS 'upvotes',
    CAST(dv.Votes as float)/CAST((v.Votes+dv.Votes) as float) AS 'downvotes'

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

Enter Parameters

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