Up vs Down votes by hour of week of Accepted Answer

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

-- Up vs Down votes by hour of week of Accepted Answer

SELECT
    DATENAME(WEEKDAY, p.CreationDate) AS [Day],
    DATEPART(HOUR, p.CreationDate) AS [Hour],
    Count(*) AS Amount,
    SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes,
    SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS DownVotes,
    (CAST(SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS float) / CAST(SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS float)) AS UpVoteDownVoteRatio
FROM
    Votes v JOIN Posts p ON v.PostId=p.AcceptedAnswerId
WHERE
    PostTypeId = 1 AND AcceptedAnswerId IS NOT NULL
GROUP BY
    PostTypeId, DATEPART(WEEKDAY, p.CreationDate), DATENAME(WEEKDAY, p.CreationDate), DATEPART(HOUR, p.CreationDate)
ORDER BY
    PostTypeId, --DATEPART(WEEKDAY, p.CreationDate), DATEPART(HOUR, p.CreationDate)
6

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached