我需要找出谁发布了最多的评论数量的用户。有两个表1)用户(Id,DisplayName) 2)评论(Id,UserId,test)。我使用了以下查询
Select DisplayName from users INNER JOIN (Select UserId, max(comment_count) as `max_comments from (Select UserId, count(Id) as comment_count from comments group by UserId) as` T1) as T2 ON users.Id=T2.UserId
但是,这将返回Id =1的用户的显示名称,而不是我想要的名称。我该如何解决这个问题?
发布于 2009-12-23 11:08:46
SELECT TOP 1
U.DisplayName,
COUNT(C.ID) AS CommentCount
FROM
Users AS U
INNER JOIN Comments AS C ON U.ID = C.UserID
GROUP BY
U.DisplayName
ORDER BY
COUNT(C.ID) DESC
https://stackoverflow.com/questions/1952123
复制