下面的查询查找针对用户的每个标签的答案总数。它不会考虑用户的自我回答的问题,因为它几乎没有额外的计数。
--Self answered questions dont countselect t.TagName, COUNT(q.Id) as countofAnsweredQuestionsfrom Posts qinner join PostTags AS ptON pt.PostId = q.Idinner join Posts aon a.parentId = q.Idinner join Tags as ton pt.tagId = t.Idwhere q.CommunityOwnedDate is null and q.ClosedDate is null and a.OwnerUserId = ##UserId## and q.OwnerUserId != ##UserId## and a.postTypeId = 2GROUP BY t.TagNameORDER BY countofAnsweredQuestions desc



