假设我的表格如下:
username userid
a1 1
a1 1
a1 1
b2 2
c2 3
d2 3
最受欢迎的用户名:a1
如何找到表格中最受欢迎的项目?
答案 0 :(得分:4)
SELECT username, count(*) AS frequency
FROM your_table
GROUP BY username
ORDER BY frequency DESC
LIMIT 1
会产生一行:
username | frequency
---------+----------
a1 3