1

如前所述 meta

我想创建一个数据资源管理器查询来显示 StackOverflow 上前 100 名最不知名的用户。

我所说的前 100 名是按降序排列的零接受答案的最大百分比排序的列表。

这是我第一次尝试使用 SQL,我正在研究其他查询并认为就是这样:

SELECT TOP 100
    u.Id as [User Link],
    count(a.Id) as [Answers],
(select sum(CASE WHEN a.Score = 0 then 1 else 0 end) * 1000 / count(a.Id) / 10.0) as [Percentage]
from
    Users u
    inner join
    Posts q on q.AcceptedAnswerId = u.Id
    inner join
    Posts a
    on a.Id = q.AcceptedAnswerId
where
      a.CommunityOwnedDate is null
      and a.postTypeId = 2
      and u.Reputation > 1000
group by u.Id
order by Percentage DESC

结果:https ://data.stackexchange.com/stackoverflow/query/218910

结果显示用户只有一个答案,当您检查他们的个人资料时,这不是真的。

4

1 回答 1

2

您可以使用 Sam Saffron 的The true unsung heros查询来提取此信息。我稍微修改了一下,只包含前 100 名。

select top 100 
  X.*, u.Reputation from (
  select a.OwnerUserId [User Link], 
  sum(case when a.Score = 0 then 0 else 1 end) as [Non Zero Score Answers],  
  sum(case when a.Score = 0 then 1 else 0 end) as [Zero Score Answers]
from Posts q
join Posts a on a.Id = q.AcceptedAnswerId 
where a.CommunityOwnedDate is null and a.OwnerUserId is not null
 and a.OwnerUserId <> isnull(q.OwnerUserId,-1)
group by a.OwnerUserId
having sum(case when a.Score = 0 then 1 else 0 end) > 10
) as X 
join Users u on u.Id = [User Link]
order by --[Zero Score Answers] desc, 
([Zero Score Answers]+ 0.0) / ([Zero Score Answers]+ [Non Zero Score Answers]+ 0.0) desc

这按零分答案与总答案的比率排序。

于 2014-10-02T14:20:19.193 回答