WITH MonthlyVotes AS ( SELECT YEAR(v.CreationDate) AS Yea...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Earth Science

Q&A for those interested in the geology, meteorology, oceanography, and environmental sciences

WITH MonthlyVotes AS (
    SELECT
        YEAR(v.CreationDate) AS YearValue,
        MONTH(v.CreationDate) AS MonthValue,
        SUM(CASE WHEN v.VoteTypeId = 2 THEN 1 ELSE 0 END) AS Upvotes,
        SUM(CASE WHEN v.VoteTypeId = 3 THEN 1 ELSE 0 END) AS Downvotes
    FROM
        Votes v
        JOIN Posts ON v.PostId = Posts.Id
        JOIN PostTags ON Posts.Id = PostTags.PostId
        JOIN Tags ON PostTags.TagId = Tags.Id
    --WHERE
    --    Tags.TagName LIKE '%##TagName##%'
    GROUP BY
        YEAR(v.CreationDate),
        MONTH(v.CreationDate)
)

SELECT
    --(YearValue * 100) + MonthValue AS YearMonthNumeric,
    (YearValue - YEAR(GETDATE())) * 12 + MonthValue AS YearMonthNumeric,
    Upvotes,
    Downvotes
FROM
    MonthlyVotes
ORDER BY
    YearValue DESC,
    MonthValue DESC;

Enter Parameters

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