Queries counts for the Answered, Closed, Accepted stats
プログラマーと熱狂的なプログラマーのためのサイトに関する質問と回答
--@Merlin we want to know the percentage of questions which are: --unanswered, that are not closed or wiki. --low rep users (i.e < 12) have an up voted answer but no accepted answer --percentage of unanswered questions by asker's reputation --SET NOCOUNT ON; -- doesn't seem to work in data.SE --GO DECLARE @unanswered int = 0; DECLARE @answered int = 0; DECLARE @closedwo int = 0; WITH TaggedPosts(PostId) AS ( SELECT pt.PostId as PostId FROM PostTags pt INNER JOIN Tags t ON t.Id=pt.TagId WHERE t.TagName LIKE '%' + ##tag:string## + '%' GROUP BY pt.PostId ) SELECT CASE WHEN p.AcceptedAnswerId IS NULL THEN 'N' ELSE 'Y' END AS [Accepted], CASE WHEN p.ClosedDate IS NULL THEN 'N' ELSE 'Y' END AS [Closed], CASE WHEN p.AnswerCount = 0 THEN 'N' ELSE 'Y' END AS [Answers], count(tp.PostId) as Questions FROM TaggedPosts tp INNER JOIN Posts p ON p.Id=tp.PostId WHERE PostTypeId = 1 GROUP BY CASE WHEN p.AcceptedAnswerId IS NULL THEN 'N' ELSE 'Y' END, CASE WHEN p.ClosedDate IS NULL THEN 'N' ELSE 'Y' END, CASE WHEN p.AnswerCount = 0 THEN 'N' ELSE 'Y' END ORDER BY Accepted, Closed, Answers