DECLARE @AID int = ##AnswerID## SELECT DATEFROMPARTS(YEA...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Physics

Q&A for active researchers, academics and students of physics

DECLARE @AID int = ##AnswerID##

SELECT
    DATEFROMPARTS(YEAR(v.CreationDate), MONTH(v.CreationDate), 1) AS [Year-Month],
    v.postid AS [Post Link],
    COUNT(CASE WHEN v.VoteTypeId = 2 THEN 1 ELSE NULL END) AS [Upvotes],
    COUNT(CASE WHEN v.VoteTypeId = 3 THEN 1 ELSE NULL END) AS [Downvotes],
    COUNT(*) AS [U&D_Votes],
    q.ViewCount,
    SUM(q.ViewCount) AS [ViewCount]

FROM Posts p
    INNER JOIN
        Votes v ON v.postid = p.id
    INNER JOIN 
        Posts q ON q.id = p.parentid

WHERE p.id = @AID
    AND v.VoteTypeId IN (2, 3) -- Limit to Up/ Downvotes
    AND (v.CreationDate >= '##Date1?2016-07-01##') AND (v.CreationDate <= '##Date2?2021-07-01##')
    --AND (q.ViewCount >= '##Date1?2016-07-01##') AND (q.ViewCount <= '##Date2?2021-07-01##')

GROUP BY DATEFROMPARTS(YEAR(v.CreationDate), MONTH(v.CreationDate), 1), v.postid, 
    q.ViewCount

ORDER BY DATEFROMPARTS(YEAR(v.CreationDate), MONTH(v.CreationDate), 1) ASC

Enter Parameters

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