PHP获取表格中最受欢迎的项目(PHP Get the most popular item in table)

编程入门 行业动态 更新时间:2024-10-24 14:19:29
PHP获取表格中最受欢迎的项目(PHP Get the most popular item in table) mysql

让我说我的表看起来像:

username userid a1 1 a1 1 a1 1 b2 2 c2 3 d2 3

最受欢迎的用户名: a1

如何在表格中找到最受欢迎的项目?

lets say that my table looks like:

username userid a1 1 a1 1 a1 1 b2 2 c2 3 d2 3

the most popular username:a1

How do I find the most popular item in table?

最满意答案

SELECT username, count(*) AS frequency FROM your_table GROUP BY username ORDER BY frequency DESC LIMIT 1

会产生一行:

username | frequency ---------+---------- a1 3 SELECT username, count(*) AS frequency FROM your_table GROUP BY username ORDER BY frequency DESC LIMIT 1

would yield a single row:

username | frequency ---------+---------- a1 3

更多推荐

本文发布于:2023-07-29 20:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319419.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最受欢迎   表格   项目   PHP   item

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!