有人知道如何在我的 MySQL 数据库中获取 5 个最常见的字符串吗?
我想要在我的蜜 jar 上使用的最常见的 2 个用户名,并在一个小的 HTML 表格中以降序显示(所以最常见的在前)。
MySQL 表:蜜 jar
表列:用户
我的表格是这样的:
[attempt_ID] [user] [password]
1 Foo Bar
2 Bar Foo
3 Foo Test
4 Bar Foo
5 Foo Nyancat123
6 Bar DikkeBMW
7 Foo Password
8 John Doe
我只需要用户名,而不是密码。 我认为它应该看起来像这样:
[user] [count]
Foo 4
Bar 3
我已经看过 This线程,但我无法从中得到任何东西,因为我不太了解 MySQL...
最佳答案
试试这个:
假设普通 user_name
至少有 count >1
select user_name,count(*) as count from tbl
group by user_name having count>1 order by count desc limit 5;
关于mysql - 获取表中最常见的 5 个用户名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34789765/