使用 SQL,我有一个包含用户名列表的表,我试图在不使用 MAX 的情况下输出重复次数最多的一个。我对 SQL 很陌生,所以任何帮助将不胜感激!
谢谢
您可以使用聚合函数来获取 a重复count()
的总次数:username
select username, count(username) Total
from yourtable
group by username
order by total desc
然后根据您的数据库,您可以返回出现最多的用户名。
在 MySQL 中,您可以使用LIMIT
:
select username, count(username) Total
from yourtable
group by username
order by total desc
limit 1;
在 SQL Server 中,您可以使用TOP
:
select TOP 1 with Ties username, count(username) Total
from yourtable
group by username
order by total desc