首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何计算dataexplorer中每个帖子中最常见的CloseReasonTypes数?

如何计算dataexplorer中每个帖子中最常见的CloseReasonTypes数?
EN

Stack Overflow用户
提问于 2014-05-12 12:25:49
回答 1查看 72关注 0票数 1

我开始撰写这个查询,我发现很难理解为什么要结束这个问题。

代码语言:javascript
复制
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值相关:这就引出了两个问题:

  • First:在查看这个查询之后,我应该加入CloseReasonTypes to PendingFlags,以显示原因名而不是它们的编号。由于Posts和PendingFlags之间没有共同的字段,但是由于我使用from posts作为连接表的基础,所以我不知道如何进行这个连接。
  • Secound:我不知道在每一行中选择最常用的关闭原因。虽然有几个问题似乎已经讨论过类似的情况,但我不能使用他们的答案,因为他们询问如何在整个表上找到最常见的值,从而生成一个只有一列和一行的表,而我需要对每个帖子上的标志计数。
EN

回答 1

Stack Overflow用户

发布于 2014-05-12 13:49:58

虽然不完全是你想要的,但我相信这个查询会给你一个好的开始。

代码语言:javascript
复制
select
    PostId as [Post Link], 
    duplicate = sum(case when closereasontypeid = 101 then 1 else 0 end), 
    offtopic = sum(case when closereasontypeid = 102 then 1 else 0 end),
    unclear = sum(case when closereasontypeid = 103 then 1 else 0 end),
    toobroad = sum(case when closereasontypeid = 104 then 1 else 0 end),
    opinion = sum(case when closereasontypeid = 105 then 1 else 0 end),
    ot_superuser = sum(case when CloseAsOffTopicReasonTypeId = 4 then 1 else 0 end),
    ot_findexternal = sum(case when CloseAsOffTopicReasonTypeId = 8 then 1 else 0 end),
    ot_serverfault = sum(case when CloseAsOffTopicReasonTypeId = 7 then 1 else 0 end),
    ot_lackinfo = sum(case when CloseAsOffTopicReasonTypeId = 12 then 1 else 0 end),
    ot_typo = sum(case when CloseAsOffTopicReasonTypeId = 11 then 1 else 0 end)
from pendingflags
where 
    flagtypeid in (13,14)   -- Close flags
    and creationdate > '2014-04-15'
group by PostId

这仅仅是看今年4月15日以来关闭的邮件,并返回了大约23500个记录。

我认为数据资源管理器不包含已删除的帖子,因此这些帖子不包含在结果中。

如果/当添加或删除新的关闭原因时,这将需要修改。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23609014

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档