Accounting only for votes cast on questions less than 31 days after the question was created.
Q&A about the site for Joomla! administrators, users, developers and designers
WITH QuestStatsByMonth AS (
SELECT DATEADD (month, DATEDIFF (month, 0, q.CreationDate), 0) AS [Month],
SUM (q.Score) AS TotalScore,
COUNT (q.Id) AS NumQuestions,
COUNT (v.Id) AS Votes
FROM Posts q
JOIN Votes v ON q.Id = v.PostId AND (v.VoteTypeId=2 OR v.VoteTypeId=3)
WHERE q.PostTypeId = 1
GROUP BY DATEADD (month, DATEDIFF (month, 0, q.CreationDate), 0)
q.Votes AS 'votes'
FROM QuestStatsByMonth q
ORDER BY q.[Month]