使用 Stack Exchange Data Explorer (SEDE) 按 post 计数和声誉查找用户

Using Stack Exchange Data Explorer (SEDE) to find users by post count and reputation

我想找出哪些用户的 post 数量最少(少于 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;

原始用户post计数示例查询在data.stackexchange.com/Whosebug/query/503051

这就是 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.