Votes per month

0

Please login or register to vote for this query.

(click on this box to dismiss)

Moderators

Q&A for community managers, administrators, and moderators

SELECT DATEADD(MONTH, M, 0) AS Month,
       ( 1 - GROUPING(M) ) * SUM(IIF(VoteTypeId = 2, 1, 0)) AS UpVotes,
       ( 1 - GROUPING(M) ) * SUM(IIF(VoteTypeId = 3, 1, 0)) AS DownVotes
FROM   Votes
       CROSS APPLY (VALUES (DATEDIFF(MONTH, 0, CreationDate))) V(M)
WHERE  VoteTypeId IN ( 2, 3 )
       AND CreationDate >= '2000-01-01'
       AND CreationDate < '2020-12-31'
       GROUP  BY GROUPING SETS ( ( ), ( M ) )

Enter Parameters

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