我正在尝试创建一个查询,以查找与每个标签相对应的答案总数(我在stackoverflow中给出)。
通过此操作,我可以找到已接受,计分和未计分答案的总数。
并使用它,我可以找到每个标签有多少个投票。
我在data.StackExcange中运行以下查询以获取所需的结果,但未成功。
这是我的查询:
DECLARE @UserId int = ##UserId## SELECT --TOP 20 TagName, count(a.Id) as [Accepted Answers] from Posts q inner join Posts a on a.Id = q.AcceptedAnswerId WHERE Posts.OwnerUserId = @UserId a.CommunityOwnedDate is null and a.OwnerUserId = ##UserId## and q.OwnerUserId != ##UserId## and a.postTypeId = 2 GROUP BY TagName
更新1:
我还必须找到问题的网址,标题以及与该答案相对应的所有其他标签。
下面的查询查找针对用户的每个标签的答案总数。它不会考虑用户的自我回答的问题,因为它几乎没有额外的计数。
--Self answered questions dont count select t.TagName, COUNT(q.Id) as countofAnsweredQuestions from Posts q inner join PostTags AS pt ON pt.PostId = q.Id inner join Posts a on a.parentId = q.Id inner join Tags as t on pt.tagId = t.Id where q.CommunityOwnedDate is null and q.ClosedDate is null and a.OwnerUserId = ##UserId## and q.OwnerUserId != ##UserId## and a.postTypeId = 2 GROUP BY t.TagName ORDER BY countofAnsweredQuestions desc