使用 Stack Exchange Data Explorer (SEDE) 按帖子计数和信誉查找用户

Posted

技术标签:

【中文标题】使用 Stack Exchange Data Explorer (SEDE) 按帖子计数和信誉查找用户【英文标题】:Using Stack Exchange Data Explorer (SEDE) to find users by post count and reputation 【发布时间】:2019-04-04 14:09:49 【问题描述】:

我想找出哪些用户在帖子数量最少(少于 10 个)的情况下享有最高声誉。但是为什么我不能在这个加入之前有一个where 子句? :

SELECT TOP 100 Users.Id, Users.DisplayName AS [Username], Users.Reputation, COUNT(Posts.Id) AS [Post Count] FROM Users
//WHERE COUNT(Posts.Id) < 10
JOIN Posts ON Posts.OwnerUserId = Users.Id 
GROUP BY Users.Id, Users.DisplayName, Users.Reputation
ORDER BY Users.Reputation DESC;

原始用户帖子计数示例查询位于data.stackexchange.com/***/query/503051

【问题讨论】:

【参考方案1】:

这就是the HAVING clause (MS reference) 的用途。

你会使用:

SELECT TOP 100 Users.Id, Users.DisplayName AS [Username], Users.Reputation, COUNT(Posts.Id) AS [Post Count] FROM Users
JOIN Posts ON Posts.OwnerUserId = Users.Id
GROUP BY Users.Id, Users.DisplayName, Users.Reputation
HAVING COUNT(Posts.Id) < 10
ORDER BY Users.Reputation DESC;

但在这里,利用几个SEDE features:

-- maxRows: How many rows to return:
-- maxPosts: Maximum number of posts a user can have:

SELECT TOP ##maxRows:INT?100##
            'site://u/' + CAST(u.Id AS NVARCHAR) + '|' + u.DisplayName  AS [User]
            , u.Reputation
            , COUNT (p.Id)  AS [Post Count]
FROM        Users u
LEFT JOIN   Posts p         ON (p.OwnerUserId = u.Id  AND  p.PostTypeId IN (1, 2) )  -- Q & A only
GROUP BY    u.Id
            , u.DisplayName
            , u.Reputation
HAVING      COUNT (p.Id) <= ##maxPosts:INT?10##
ORDER BY    u.Reputation DESC
            , [Post Count]
            , u.DisplayName

你可以see it live in SEDE

我特别喜欢the users with higher rep that have no posts。

【讨论】:

以上是关于使用 Stack Exchange Data Explorer (SEDE) 按帖子计数和信誉查找用户的主要内容,如果未能解决你的问题,请参考以下文章

EX2010与EX2013共存迁移03-Exchange 2013共存部署-分角色部署

Exchange2010与Office365混合部署升级到Exchange2016混合部署——Ex2016 EAC迁入Ex2010用户

Exchange 2010和Exchange 2016共存部署-5:向导安装EX16邮箱服务器

Exchange 2010和Exchange 2016共存部署-6:无人参与安装EX16邮箱服务器

Exchange2010与Office365混合部署升级到Exchange2016混合部署——Ex2010迁移接收连接器到Ex2016

EX2010与EX2013共存迁移04-Exchange 2013配置