How many posts have been closed by each close reason

2

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

-- 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'),
    (101, 'duplicate'),
    (102, 'off-topic'),
    (103, 'unclear what you''re asking'),
    (104, 'too broad'),
    (105, 'primarily opinion-based')

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

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results