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 3the 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 1would yield a single row:
username | frequency ---------+---------- a1 3更多推荐
发布评论