【问题标题】:SQL - DataExplorer Query Top Unsung UsersSQL - DataExplorer 查询热门无名用户
【发布时间】:2014-10-08 18:55:36
【问题描述】:

As previously discussed on 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

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

【问题讨论】:

    标签: sql stackexchange dataexplorer


    【解决方案1】:

    您可以使用 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
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 2013-05-24
      • 2013-10-09
      • 1970-01-01
      相关资源
      最近更新 更多