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]