Q&A about the site for members of the workforce navigating the professional setting
DECLARE @now DATETIME = ( SELECT TOP 1 DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) FROM Posts ORDER BY Id DESC ); WITH Raw AS ( SELECT DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) AS Month, COUNT(*) AS CreatedCount, COUNT(CASE WHEN ClosedDate IS NOT NULL OR DeletionDate IS NOT NULL OR Score < 0 THEN 1 END) AS RejectedCount FROM PostsWithDeleted WHERE PostTypeId = 1 GROUP BY DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) ) SELECT Month, CASE WHEN ##ShowPercentage:int?0## <> 0 THEN 100.0 * RejectedCount / CreatedCount END AS RejectionPct, CASE WHEN ##ShowPercentage## = 0 THEN RejectedCount END AS RejectedCount, CASE WHEN ##ShowPercentage## = 0 THEN CreatedCount END AS CreatedCount FROM Raw WHERE Month < @now ORDER BY Month DESC