1

如何在sql中显示列中重复次数最高的字段?

例如,如果一列包含:

杰克
杰克
约翰
约翰
约翰

如何显示上列中的最大重复字段(即)约翰?

4

2 回答 2

1
select chairman
from mytable
group by chairman
HAVING COUNT(*) = (
select TOP 1 COUNT(*)
from mytable
group by chairman
ORDER BY COUNT(*) DESC)
于 2013-09-25T14:53:42.917 回答
0
select name from persons
group by name
having count(*) = (
  select count(*) from persons
  group by name
  order by count(*) desc
  limit 1)
于 2013-09-25T14:51:12.927 回答