Q&A for professional and enthusiast programmers
DECLARE @TagName varchar(128) = '%##TagName##%' SELECT COUNT(P.Id) FROM Posts P WHERE P.Id IN ( SELECT DISTINCT(PT.PostId) FROM PostTags PT WHERE PT.TagId IN ( SELECT T.Id FROM Tags T WHERE T.TagName LIKE @TagName ) ) SELECT COUNT(P.Id) FROM Posts P WHERE P.Id IN ( SELECT DISTINCT(PT.PostId) FROM PostTags PT WHERE PT.TagId IN ( SELECT T.Id FROM Tags T WHERE T.TagName LIKE @TagName ) ) AND P.AcceptedAnswerId IS NOT NULL SELECT CAST(( CAST(( SELECT SUM(P.AnswerCount) FROM Posts P WHERE P.Id IN ( SELECT DISTINCT(PT.PostId) FROM PostTags PT WHERE PT.TagId IN ( SELECT T.Id FROM Tags T WHERE T.TagName LIKE @TagName ) ) ) AS FLOAT) / CAST(( SELECT COUNT(P.Id) FROM Posts P WHERE P.Id IN ( SELECT DISTINCT(PT.PostId) FROM PostTags PT WHERE PT.TagId IN ( SELECT T.Id FROM Tags T WHERE T.TagName LIKE @TagName ) ) ) AS FLOAT) ) AS DECIMAL(4,2))