T-SQL Tuesday #168 : Running totals example

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

WITH AaronPosts AS
(
SELECT [Month]   = MONTH(CreationDate),
       PostCount = COUNT(*)
  FROM Posts
  WHERE CreationDate >= '20230101'
  AND OwnerUserId = 61305
  AND PostTypeId = 2 -- answer
  GROUP BY MONTH(CreationDate)
)
SELECT [Month], 
  CountForMonth = PostCount, 
  RunningCount  = SUM(PostCount) OVER
  (
    ORDER BY [Month] ROWS UNBOUNDED PRECEDING
  )
FROM AaronPosts
ORDER BY [Month];

Enter Parameters

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