我可以获得mysql数据库中某个值的最高数量吗?
我想显示帖子最多的用户。通过计算用户名在数据库中显示的次数来添加帖子。如何获取所有元素并检查哪个值比其他值出现得更多?
所以说我的数据库看起来像这样:
id | username
1 | test
2 | test
3 | no test
“测试”显示最多,所以我怎么说
highest poster: "test"
I want to display the user with the most posts. the posts are added by counting how many times their username is displayed in the database. How can I grab all the elements and check to see which value appears more then others?
So say my database looks like this:
id | username
1 | test
2 | test
3 | no test
"test" is shown the most, so how could I say
highest poster: "test"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
此查询返回
用户名
和出现次数,按相反顺序排序,因此第一个记录是出现次数较多的记录:更新:
正如 thedugas 和 Joe Phillips 所指出的,您可以向此查询添加一个
limit 1
子句,以仅获取出现次数最多的记录This query returns
username
and number of occurrences, sorted in reverse order, so the first record is the one with more occurrences:UPDATE:
As pointed by thedugas and Joe Phillips, you can add a
limit 1
clause to this query to get only the record with the highest number of occurrences