Как посчитать наиболее частые CloseReasonTypes для сообщений в dataexplorer?
Я начал составлять этот запрос, и мне трудно понять, почему вопрос должен быть закрыт.
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
В качестве основы для объединения таблиц я понятия не имею, как это сделать.Secound: Я понятия не имею, чтобы выбрать наиболее распространенную причину закрытия в каждой строке. Хотя некоторые вопросы, по-видимому, обсуждали похожие случаи, я не могу использовать их ответы, поскольку они спрашивают, как найти наиболее распространенное значение для всей таблицы, в результате чего получается таблица с одним столбцом и одной строкой, тогда как мне нужно сделать это для подсчета флагов на каждом посте.
1 ответ
Хотя это не совсем то, что вы ищете, я считаю, что этот запрос даст вам хорошее начало.
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
Это только просмотр закрытых постов с 15 апреля этого года, и возвращает около 23 500 записей.
Я считаю, что в проводнике данных нет записей, которые были там удалены, поэтому они не включены в результаты.
Это потребует изменений, если / когда новые причины закрытия будут добавлены или удалены.