我开始编写这个查询,我发现很难理解为什么应该关闭这个问题。
select
TOP ##Limit:int?38369## -- The maximum value the hardware can handle.
Posts.Id as [Post Link], -- Question title.
Count(PendingFlags.PostId) as [Number of pending flags], -- Number of pending flags per questions.
Posts.OwnerUserId as [User Link], -- Let click on the colum to see if the same user ask off-topic questions often.
Reputation as [User Reputation], -- Interesting to see that such questions are sometimes asked by high rep users.
Posts.Score as [Votes], -- Interesting to see that some questions have more than 100 upvotes.
Posts.AnswerCount as [Number of Answers], -- I thought we shouldn't answer on off- topic post.
Posts.FavoriteCount as [Number of Stars], -- Some questions seems to be very helpfull :) .
Posts.CreationDate as [Asked on], -- The older is the question, the more is the chance that flags on them can't get reviewed.
Posts.LastActivityDate as [last activity], -- Similar effect as with Posts.CreationDate.
Posts.LastEditDate as [modified on],
Posts.ViewCount
from posts
LEFT OUTER JOIN Users on Users.id = posts.OwnerUserId
INNER JOIN PendingFlags on PendingFlags.PostId = Posts.Id
where ClosedDate IS NULL -- The question is not closed.
group by Posts.id, Posts.OwnerUserId, Reputation, Posts.Score, Posts.FavoriteCount, Posts.AnswerCount, Posts.CreationDate, Posts.LastActivityDate, Posts.LastEditDate, Posts.ViewCount
order by Count(PendingFlags.PostId) desc; -- Questions with more flags have more chance to get them handled, and the higher is the probabilty that the question is off-topic (since several users already reviewed the question).
鉴于每个问题都有几个标志,我不能使用一个简单的表格来显示标志用于每个标志的原因,但我认为应该与每个帖子最常见的 CloseReasonTypes.Id 值相关:这个导致我遇到两个问题:
首先:查看此查询后,我应该将CloseReasonTypes加入PendingFlags以显示原因名称而不是其编号。由于Posts和PendingFlags之间没有公共字段,但是当我
from posts
用作连接表的基础时,我不知道如何执行此JOIN。第二:我不知道在每一行上选择最常用的关闭原因。虽然有几个问题似乎已经讨论过类似的情况,但我不能使用他们的答案,因为他们询问如何在整个表上找到最常见的值,从而产生一个单列单行的表,而我需要这样做是为了计算每个帖子上的标志。