[英]MySQL - get max value of count
I'm trying to only select Nicknames with the maximum number of posts but I can't seem to be able to get it done... Needless to say the code below doesn't work but this is what I got so far. 我试图仅选择帖子数量最多的昵称,但似乎无法完成...不用说下面的代码不起作用,但这是我到目前为止的结果。
SELECT Person.Nickname FROM Posting, Person
WHERE Person.Nickname=Posting.Nickname
AND count(Posting.PostingID)=(select max(count(Posting.PostingID)))
GROUP BY Person.Nickname
ORDER BY Person.Nickname ASC;
It would be great if someone could help! 如果有人可以帮助,那就太好了! I'm slowely but surely getting REALLY frustrated and I feel that my problem is something really easy that I'm just overlooking...
我很慢,但是肯定感到非常沮丧,我觉得我的问题确实很容易被忽略。
Thx in advance for your help! 提前感谢您的帮助!
Edit: This is under the assumption that there is more than one person with the maximum amount of posts. 编辑:这是基于一个以上的职位数量最多的人的假设。 For example: A might have 5 Posts, B might have 4, C might have 5 Posts and so on.
例如:A可能有5个帖子,B可能有4个帖子,C可能有5个帖子,依此类推。
The output should then be: A,C,... 输出应为:A,C,...
You don't need person table you can get it from Posting 您不需要人员表,可以从发布中获取
SELECT Nickname FROM Posting GROUP BY .Nickname having count(Posting.PostingID) =
(SELECT count(Posting.PostingID) FROM Posting
GROUP BY .Nickname
ORDER BY count(Posting.PostingID) desc LIMIT 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.