Posts count in the last X months + Bar of counts

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @NumMonths INT = 24;  -- number of months
DECLARE @DivisionFactor INT = 5000;  -- division factor

SELECT	[YEAR] = YEAR(CreationDate),
		[MONTH] = MONTH(CreationDate),
		COUNT_ID = FORMAT(COUNT(Id), 'N0'),
		'|' = '|',
		DIV_COUNT_ID = COUNT(Id) / @DivisionFactor,
		BAR_COUNT_ID = REPLICATE('*', COUNT(Id) / @DivisionFactor)
FROM Posts
WHERE CreationDate >= DATEADD(MONTH, -@NumMonths, GETDATE())
GROUP BY YEAR(CreationDate), MONTH(CreationDate)
ORDER BY [YEAR], [MONTH]

Enter Parameters

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