Summary of the number of questions closed by the close reason type.
Q&A for people looking to bypass life's everyday problems with simple tricks
-- Distribution of Close Reasons -- Summary of the number of questions closed by the close reason type. DECLARE @closeReasons table ( Id int NOT NULL PRIMARY KEY, Name nvarchar(200) NOT NULL ) INSERT INTO @closeReasons VALUES (1, 'Exact duplicate'), (2, 'Off topic'), (3, 'Subjective and argumentative'), (4, 'Not a real question'), (7, 'Too localized'), (20, 'Noise or pointless') SELECT (CASE WHEN cr.Name IS NULL THEN '(Unknown)' ELSE cr.Name END) AS 'Close Reason', CAST(PostHistory.Comment AS int) AS CloseReasonId, SUM(1) AS Count FROM PostHistory LEFT OUTER JOIN @closeReasons cr ON cr.Id = CAST(PostHistory.Comment AS int) WHERE PostHistoryTypeId = 10 GROUP BY cr.Name, CAST(PostHistory.Comment AS int) ORDER BY Count DESC