Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 获取表中最常见的5个用户名_Mysql - Fatal编程技术网

Mysql 获取表中最常见的5个用户名

Mysql 获取表中最常见的5个用户名,mysql,Mysql,知道如何在MySQL数据库中获取5个最常见字符串的人 我想要在我的蜜罐上使用的最常用的两个用户名,并在一个小的HTML表中降序显示它们(所以最常用的是第一个) MySQL表:蜜罐 表列:用户 我的桌子看起来像这样: [attempt_ID] [user] [password] 1 Foo Bar 2 Bar Foo 3 Foo Test 4

知道如何在MySQL数据库中获取5个最常见字符串的人

我想要在我的蜜罐上使用的最常用的两个用户名,并在一个小的HTML表中降序显示它们(所以最常用的是第一个)

MySQL表:蜜罐
表列:用户

我的桌子看起来像这样:

[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
我已经看过线程了,但我对它一无所知,因为我不太了解MySQL…

试试这个:

假设公共
用户名
的计数至少大于1

select user_name,count(*) as count from tbl
group by user_name having count>1 order by count desc limit 5;
试试这个:

假设公共
用户名
的计数至少大于1

select user_name,count(*) as count from tbl
group by user_name having count>1 order by count desc limit 5;

它返回最多出现5次的用户

SELECT user_name,COUNT(1) AS count_user 
FROM table
GROUP BY user_name 
ORDER BY count_user DESC
LIMIT 5;

它返回最多出现5次的用户

SELECT user_name,COUNT(1) AS count_user 
FROM table
GROUP BY user_name 
ORDER BY count_user DESC
LIMIT 5;

select user,count(*)as total from table_name group by user order by total desc limit 2
完成此技巧的,谢谢
select user,count(*)as total from table_name group by user order by total desc limit 2
完成此技巧的,谢谢不完全正确,请参阅问题下的第一条注释。不,完全正确,重新阅读第一条评论,它包含一个订单。限制5不能保证产生想要的5,除非您使用order byNot完全正确,请参阅问题下的第一条注释。否,完全正确,请重新阅读第一条注释,它包括订单。限制5不保证生产所需的5,除非您使用订购方式